Test RealmBarDataSet, fix stack-size issue
This commit is contained in:
parent
0c729ac64c
commit
faa02b87ea
6 changed files with 22 additions and 11 deletions
|
@ -5,11 +5,15 @@ import android.os.Bundle;
|
|||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.animation.Easing;
|
||||
import com.github.mikephil.charting.charts.BarChart;
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
import com.github.mikephil.charting.components.YAxis;
|
||||
import com.github.mikephil.charting.data.BarData;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.LineData;
|
||||
import com.github.mikephil.charting.data.realm.RealmBarDataSet;
|
||||
import com.github.mikephil.charting.data.realm.RealmLineDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
@ -26,16 +30,16 @@ import io.realm.RealmResults;
|
|||
*/
|
||||
public class RealmDatabaseActivity extends RealmBaseActivity {
|
||||
|
||||
private LineChart mChart;
|
||||
private BarChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_linechart_noseekbar);
|
||||
setContentView(R.layout.activity_barchart);
|
||||
|
||||
mChart = (LineChart) findViewById(R.id.chart1);
|
||||
mChart = (BarChart) findViewById(R.id.chart1);
|
||||
mChart.setDrawGridBackground(false);
|
||||
|
||||
// no description text
|
||||
|
@ -81,14 +85,14 @@ public class RealmDatabaseActivity extends RealmBaseActivity {
|
|||
|
||||
RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);
|
||||
|
||||
RealmLineDataSet<RealmDemoData> set = new RealmLineDataSet<RealmDemoData>(result, "value", "xIndex");
|
||||
RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "value", "xIndex");
|
||||
set.setValueTextSize(9f);
|
||||
|
||||
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
|
||||
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
|
||||
dataSets.add(set); // add the dataset
|
||||
|
||||
// create a data object with the dataset list
|
||||
LineData data = new LineData(result, "xValue", dataSets);
|
||||
BarData data = new BarData(result, "xValue", dataSets);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
|
|
|
@ -611,7 +611,7 @@ public abstract class ChartData<T extends IDataSet<? extends Entry>> {
|
|||
|
||||
IDataSet set = mDataSets.get(dataSetIndex);
|
||||
// add the entry to the dataset
|
||||
if(!set.addEntry(e))
|
||||
if (!set.addEntry(e))
|
||||
return;
|
||||
|
||||
float val = e.getVal();
|
||||
|
@ -956,6 +956,13 @@ public abstract class ChartData<T extends IDataSet<? extends Entry>> {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the given Realm-ResultSet into a String array by using the provided xValuesField.
|
||||
*
|
||||
* @param result
|
||||
* @param xValuesField
|
||||
* @return
|
||||
*/
|
||||
protected static List<String> toXVals(RealmResults<? extends RealmObject> result, String xValuesField) {
|
||||
|
||||
List<String> xVals = new ArrayList<>();
|
||||
|
|
|
@ -51,7 +51,7 @@ public class RealmBarDataSet<T extends RealmObject> extends RealmBaseDataSet<T,
|
|||
|
||||
@Override
|
||||
public String[] getStackLabels() {
|
||||
return new String[0];
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,7 +23,7 @@ public interface IBarDataSet extends IBarLineScatterCandleBubbleDataSet<BarEntry
|
|||
|
||||
/**
|
||||
* Returns the maximum number of bars that can be stacked upon another in
|
||||
* this DataSet.
|
||||
* this DataSet. This should return 1 for non stacked bars, and > 1 for stacked bars.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
|
|
@ -55,7 +55,7 @@ public class BarChartRenderer extends DataRenderer {
|
|||
|
||||
for (int i = 0; i < mBarBuffers.length; i++) {
|
||||
IBarDataSet set = barData.getDataSetByIndex(i);
|
||||
mBarBuffers[i] = new BarBuffer(set.getEntryCount() * 4 * set.getStackSize(),
|
||||
mBarBuffers[i] = new BarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1),
|
||||
barData.getGroupSpace(),
|
||||
barData.getDataSetCount(), set.isStacked());
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class HorizontalBarChartRenderer extends BarChartRenderer {
|
|||
|
||||
for (int i = 0; i < mBarBuffers.length; i++) {
|
||||
IBarDataSet set = barData.getDataSetByIndex(i);
|
||||
mBarBuffers[i] = new HorizontalBarBuffer(set.getEntryCount() * 4 * set.getStackSize(),
|
||||
mBarBuffers[i] = new HorizontalBarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1),
|
||||
barData.getGroupSpace(),
|
||||
barData.getDataSetCount(), set.isStacked());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue