Search in sources :

Example 1 with RealmLineDataSet

use of com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet in project MPAndroidChart by PhilJay.

the class RealmWikiExample method setData.

private void setData() {
    // LINE-CHART
    final RealmResults<Score> results = mRealm.where(Score.class).findAll();
    IAxisValueFormatter formatter = new IAxisValueFormatter() {

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return results.get((int) value).getPlayerName();
        }
    };
    lineChart.getXAxis().setValueFormatter(formatter);
    barChart.getXAxis().setValueFormatter(formatter);
    RealmLineDataSet<Score> lineDataSet = new RealmLineDataSet<Score>(results, "scoreNr", "totalScore");
    lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    lineDataSet.setLabel("Result Scores");
    lineDataSet.setDrawCircleHole(false);
    lineDataSet.setColor(ColorTemplate.rgb("#FF5722"));
    lineDataSet.setCircleColor(ColorTemplate.rgb("#FF5722"));
    lineDataSet.setLineWidth(1.8f);
    lineDataSet.setCircleRadius(3.6f);
    ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
    dataSets.add(lineDataSet);
    LineData lineData = new LineData(dataSets);
    styleData(lineData);
    // set data
    lineChart.setData(lineData);
    lineChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
    // BAR-CHART
    RealmBarDataSet<Score> barDataSet = new RealmBarDataSet<Score>(results, "scoreNr", "totalScore");
    barDataSet.setColors(new int[] { ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4") });
    barDataSet.setLabel("Realm BarDataSet");
    ArrayList<IBarDataSet> barDataSets = new ArrayList<IBarDataSet>();
    barDataSets.add(barDataSet);
    BarData barData = new BarData(barDataSets);
    styleData(barData);
    barChart.setData(barData);
    barChart.setFitBars(true);
    barChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
Also used : ArrayList(java.util.ArrayList) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) AxisBase(com.github.mikephil.charting.components.AxisBase) RealmLineDataSet(com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet) LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) RealmBarDataSet(com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet) BarData(com.github.mikephil.charting.data.BarData) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet)

Example 2 with RealmLineDataSet

use of com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet in project MPAndroidChart by PhilJay.

the class RealmDatabaseActivityLine method setData.

private void setData() {
    RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
    RealmLineDataSet<RealmDemoData> set = new RealmLineDataSet<RealmDemoData>(result, "xValue", "yValue");
    set.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    set.setLabel("Realm LineDataSet");
    set.setDrawCircleHole(false);
    set.setColor(ColorTemplate.rgb("#FF5722"));
    set.setCircleColor(ColorTemplate.rgb("#FF5722"));
    set.setLineWidth(1.8f);
    set.setCircleRadius(3.6f);
    ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
    // add the dataset
    dataSets.add(set);
    // create a data object with the dataset list
    LineData data = new LineData(dataSets);
    styleData(data);
    // set data
    mChart.setData(data);
    mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
Also used : LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) ArrayList(java.util.ArrayList) RealmDemoData(com.xxmassdeveloper.mpchartexample.custom.RealmDemoData) RealmLineDataSet(com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet)

Aggregations

LineData (com.github.mikephil.charting.data.LineData)2 RealmLineDataSet (com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet)2 ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)2 ArrayList (java.util.ArrayList)2 AxisBase (com.github.mikephil.charting.components.AxisBase)1 BarData (com.github.mikephil.charting.data.BarData)1 RealmBarDataSet (com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet)1 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)1 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)1 RealmDemoData (com.xxmassdeveloper.mpchartexample.custom.RealmDemoData)1