Search in sources :

Example 31 with BarData

use of com.github.mikephil.charting.data.BarData in project Gadgetbridge by Freeyourgadget.

the class AbstractWeekChartFragment method refreshWeekBeforeData.

private DefaultChartsData<BarData> refreshWeekBeforeData(DBHandler db, BarChart barChart, Calendar day, GBDevice device) {
    // do not modify the caller's argument
    day = (Calendar) day.clone();
    day.add(Calendar.DATE, -7);
    List<BarEntry> entries = new ArrayList<>();
    ArrayList<String> labels = new ArrayList<String>();
    for (int counter = 0; counter < 7; counter++) {
        ActivityAmounts amounts = getActivityAmountsForDay(db, day, device);
        entries.add(new BarEntry(counter, getTotalsForActivityAmounts(amounts)));
        labels.add(day.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, mLocale));
        day.add(Calendar.DATE, 1);
    }
    BarDataSet set = new BarDataSet(entries, "");
    set.setColors(getColors());
    set.setValueFormatter(getBarValueFormatter());
    BarData barData = new BarData(set);
    //prevent tearing other graph elements with the black text. Another approach would be to hide the values cmpletely with data.setDrawValues(false);
    barData.setValueTextColor(Color.GRAY);
    LimitLine target = new LimitLine(mTargetValue);
    barChart.getAxisLeft().removeAllLimitLines();
    barChart.getAxisLeft().addLimitLine(target);
    return new DefaultChartsData(barData, new PreformattedXIndexLabelFormatter(labels));
}
Also used : BarDataSet(com.github.mikephil.charting.data.BarDataSet) ActivityAmounts(nodomain.freeyourgadget.gadgetbridge.model.ActivityAmounts) BarData(com.github.mikephil.charting.data.BarData) ArrayList(java.util.ArrayList) LimitLine(com.github.mikephil.charting.components.LimitLine) BarEntry(com.github.mikephil.charting.data.BarEntry)

Example 32 with BarData

use of com.github.mikephil.charting.data.BarData in project LeMondeRssReader by MBach.

the class GraphExtractor method generate.

Object generate() {
    BarChart barChart = new BarChart(context);
    List<BarEntry> yVals1 = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
        float mult = 5;
        float val = (float) (Math.random() * mult);
        yVals1.add(new BarEntry(i, val));
    }
    BarDataSet set1 = new BarDataSet(yVals1, "The year 2017");
    List<IBarDataSet> dataSets = new ArrayList<>();
    dataSets.add(set1);
    BarData barData = new BarData(dataSets);
    barChart.setData(barData);
    return barChart;
}
Also used : BarDataSet(com.github.mikephil.charting.data.BarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) BarData(com.github.mikephil.charting.data.BarData) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) BarChart(com.github.mikephil.charting.charts.BarChart) ArrayList(java.util.ArrayList) BarEntry(com.github.mikephil.charting.data.BarEntry)

Aggregations

BarData (com.github.mikephil.charting.data.BarData)32 BarEntry (com.github.mikephil.charting.data.BarEntry)22 ArrayList (java.util.ArrayList)22 BarDataSet (com.github.mikephil.charting.data.BarDataSet)19 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)19 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)4 Paint (android.graphics.Paint)3 BarBuffer (com.github.mikephil.charting.buffer.BarBuffer)3 RealmBarDataSet (com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet)3 Transformer (com.github.mikephil.charting.utils.Transformer)3 SuppressLint (android.annotation.SuppressLint)2 HorizontalBarBuffer (com.github.mikephil.charting.buffer.HorizontalBarBuffer)2 AxisBase (com.github.mikephil.charting.components.AxisBase)2 LineData (com.github.mikephil.charting.data.LineData)2 MPPointD (com.github.mikephil.charting.utils.MPPointD)2 RealmDemoData (com.xxmassdeveloper.mpchartexample.custom.RealmDemoData)2 PointF (android.graphics.PointF)1 ListView (android.widget.ListView)1 BarChart (com.github.mikephil.charting.charts.BarChart)1 Legend (com.github.mikephil.charting.components.Legend)1