Search in sources :

Example 21 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)

Example 22 with BarData

use of com.github.mikephil.charting.data.BarData in project MPAndroidChart by PhilJay.

the class BarChartActivity method setData.

private void setData(int count, float range) {
    float start = 1f;
    ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
    for (int i = (int) start; i < start + count + 1; i++) {
        float mult = (range + 1);
        float val = (float) (Math.random() * mult);
        if (Math.random() * 100 < 25) {
            yVals1.add(new BarEntry(i, val, getResources().getDrawable(R.drawable.star)));
        } else {
            yVals1.add(new BarEntry(i, val));
        }
    }
    BarDataSet set1;
    if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
        set1 = (BarDataSet) mChart.getData().getDataSetByIndex(0);
        set1.setValues(yVals1);
        mChart.getData().notifyDataChanged();
        mChart.notifyDataSetChanged();
    } else {
        set1 = new BarDataSet(yVals1, "The year 2017");
        set1.setDrawIcons(false);
        set1.setColors(ColorTemplate.MATERIAL_COLORS);
        ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
        dataSets.add(set1);
        BarData data = new BarData(dataSets);
        data.setValueTextSize(10f);
        data.setValueTypeface(mTfLight);
        data.setBarWidth(0.9f);
        mChart.setData(data);
    }
}
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) ArrayList(java.util.ArrayList) BarEntry(com.github.mikephil.charting.data.BarEntry) SuppressLint(android.annotation.SuppressLint)

Example 23 with BarData

use of com.github.mikephil.charting.data.BarData in project MPAndroidChart by PhilJay.

the class BarChartPositiveNegative method setData.

private void setData(List<Data> dataList) {
    ArrayList<BarEntry> values = new ArrayList<BarEntry>();
    List<Integer> colors = new ArrayList<Integer>();
    int green = Color.rgb(110, 190, 102);
    int red = Color.rgb(211, 74, 88);
    for (int i = 0; i < dataList.size(); i++) {
        Data d = dataList.get(i);
        BarEntry entry = new BarEntry(d.xValue, d.yValue);
        values.add(entry);
        // specific colors
        if (d.yValue >= 0)
            colors.add(red);
        else
            colors.add(green);
    }
    BarDataSet set;
    if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
        set = (BarDataSet) mChart.getData().getDataSetByIndex(0);
        set.setValues(values);
        mChart.getData().notifyDataChanged();
        mChart.notifyDataSetChanged();
    } else {
        set = new BarDataSet(values, "Values");
        set.setColors(colors);
        set.setValueTextColors(colors);
        BarData data = new BarData(set);
        data.setValueTextSize(13f);
        data.setValueTypeface(mTf);
        data.setValueFormatter(new ValueFormatter());
        data.setBarWidth(0.8f);
        mChart.setData(data);
        mChart.invalidate();
    }
}
Also used : BarDataSet(com.github.mikephil.charting.data.BarDataSet) BarData(com.github.mikephil.charting.data.BarData) ArrayList(java.util.ArrayList) BarData(com.github.mikephil.charting.data.BarData) IValueFormatter(com.github.mikephil.charting.formatter.IValueFormatter) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) BarEntry(com.github.mikephil.charting.data.BarEntry)

Example 24 with BarData

use of com.github.mikephil.charting.data.BarData in project MPAndroidChart by PhilJay.

the class CombinedChartActivity method generateBarData.

private BarData generateBarData() {
    ArrayList<BarEntry> entries1 = new ArrayList<BarEntry>();
    ArrayList<BarEntry> entries2 = new ArrayList<BarEntry>();
    for (int index = 0; index < itemcount; index++) {
        entries1.add(new BarEntry(0, getRandom(25, 25)));
        // stacked
        entries2.add(new BarEntry(0, new float[] { getRandom(13, 12), getRandom(13, 12) }));
    }
    BarDataSet set1 = new BarDataSet(entries1, "Bar 1");
    set1.setColor(Color.rgb(60, 220, 78));
    set1.setValueTextColor(Color.rgb(60, 220, 78));
    set1.setValueTextSize(10f);
    set1.setAxisDependency(YAxis.AxisDependency.LEFT);
    BarDataSet set2 = new BarDataSet(entries2, "");
    set2.setStackLabels(new String[] { "Stack 1", "Stack 2" });
    set2.setColors(new int[] { Color.rgb(61, 165, 255), Color.rgb(23, 197, 255) });
    set2.setValueTextColor(Color.rgb(61, 165, 255));
    set2.setValueTextSize(10f);
    set2.setAxisDependency(YAxis.AxisDependency.LEFT);
    float groupSpace = 0.06f;
    // x2 dataset
    float barSpace = 0.02f;
    // x2 dataset
    float barWidth = 0.45f;
    // (0.45 + 0.02) * 2 + 0.06 = 1.00 -> interval per "group"
    BarData d = new BarData(set1, set2);
    d.setBarWidth(barWidth);
    // make this BarData object grouped
    // start at x = 0
    d.groupBars(0, groupSpace, barSpace);
    return d;
}
Also used : BarDataSet(com.github.mikephil.charting.data.BarDataSet) BarData(com.github.mikephil.charting.data.BarData) ArrayList(java.util.ArrayList) BarEntry(com.github.mikephil.charting.data.BarEntry)

Example 25 with BarData

use of com.github.mikephil.charting.data.BarData in project MPAndroidChart by PhilJay.

the class HorizontalBarChartActivity method setData.

private void setData(int count, float range) {
    float barWidth = 9f;
    float spaceForBar = 10f;
    ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
    for (int i = 0; i < count; i++) {
        float val = (float) (Math.random() * range);
        yVals1.add(new BarEntry(i * spaceForBar, val, getResources().getDrawable(R.drawable.star)));
    }
    BarDataSet set1;
    if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
        set1 = (BarDataSet) mChart.getData().getDataSetByIndex(0);
        set1.setValues(yVals1);
        mChart.getData().notifyDataChanged();
        mChart.notifyDataSetChanged();
    } else {
        set1 = new BarDataSet(yVals1, "DataSet 1");
        set1.setDrawIcons(false);
        ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
        dataSets.add(set1);
        BarData data = new BarData(dataSets);
        data.setValueTextSize(10f);
        data.setValueTypeface(mTfLight);
        data.setBarWidth(barWidth);
        mChart.setData(data);
    }
}
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) ArrayList(java.util.ArrayList) BarEntry(com.github.mikephil.charting.data.BarEntry) SuppressLint(android.annotation.SuppressLint)

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