Search in sources :

Example 21 with BarEntry

use of com.github.mikephil.charting.data.BarEntry 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 22 with BarEntry

use of com.github.mikephil.charting.data.BarEntry 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)

Example 23 with BarEntry

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

the class ScrollViewActivity method setData.

private void setData(int count) {
    ArrayList<BarEntry> yVals = new ArrayList<BarEntry>();
    for (int i = 0; i < count; i++) {
        float val = (float) (Math.random() * count) + 15;
        yVals.add(new BarEntry(i, (int) val));
    }
    BarDataSet set = new BarDataSet(yVals, "Data Set");
    set.setColors(ColorTemplate.VORDIPLOM_COLORS);
    set.setDrawValues(false);
    BarData data = new BarData(set);
    mChart.setData(data);
    mChart.invalidate();
    mChart.animateY(800);
}
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 24 with BarEntry

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

the class StackedBarActivity method onProgressChanged.

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    tvX.setText("" + (mSeekBarX.getProgress() + 1));
    tvY.setText("" + (mSeekBarY.getProgress()));
    ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
    for (int i = 0; i < mSeekBarX.getProgress() + 1; i++) {
        float mult = (mSeekBarY.getProgress() + 1);
        float val1 = (float) (Math.random() * mult) + mult / 3;
        float val2 = (float) (Math.random() * mult) + mult / 3;
        float val3 = (float) (Math.random() * mult) + mult / 3;
        yVals1.add(new BarEntry(i, new float[] { val1, val2, val3 }, 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, "Statistics Vienna 2014");
        set1.setDrawIcons(false);
        set1.setColors(getColors());
        set1.setStackLabels(new String[] { "Births", "Divorces", "Marriages" });
        ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
        dataSets.add(set1);
        BarData data = new BarData(dataSets);
        data.setValueFormatter(new MyValueFormatter());
        data.setValueTextColor(Color.WHITE);
        mChart.setData(data);
    }
    mChart.setFitBars(true);
    mChart.invalidate();
}
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) MyValueFormatter(com.xxmassdeveloper.mpchartexample.custom.MyValueFormatter)

Example 25 with BarEntry

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

the class StackedBarActivityNegative method onValueSelected.

@Override
public void onValueSelected(Entry e, Highlight h) {
    BarEntry entry = (BarEntry) e;
    Log.i("VAL SELECTED", "Value: " + Math.abs(entry.getYVals()[h.getStackIndex()]));
}
Also used : BarEntry(com.github.mikephil.charting.data.BarEntry)

Aggregations

BarEntry (com.github.mikephil.charting.data.BarEntry)36 ArrayList (java.util.ArrayList)23 BarData (com.github.mikephil.charting.data.BarData)22 BarDataSet (com.github.mikephil.charting.data.BarDataSet)20 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)14 Entry (com.github.mikephil.charting.data.Entry)5 Transformer (com.github.mikephil.charting.utils.Transformer)5 BufferedReader (java.io.BufferedReader)5 IOException (java.io.IOException)5 Paint (android.graphics.Paint)4 BarBuffer (com.github.mikephil.charting.buffer.BarBuffer)4 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)3 InputStreamReader (java.io.InputStreamReader)3 SuppressLint (android.annotation.SuppressLint)2 Drawable (android.graphics.drawable.Drawable)2 HorizontalBarBuffer (com.github.mikephil.charting.buffer.HorizontalBarBuffer)2 IValueFormatter (com.github.mikephil.charting.formatter.IValueFormatter)2 MPPointF (com.github.mikephil.charting.utils.MPPointF)2 File (java.io.File)2 FileReader (java.io.FileReader)2