Search in sources :

Example 1 with MyValueFormatter

use of com.xxmassdeveloper.mpchartexample.custom.MyValueFormatter in project MPAndroidChart by PhilJay.

the class StackedBarActivity method onProgressChanged.

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    tvX.setText(String.valueOf(seekBarX.getProgress()));
    tvY.setText(String.valueOf(seekBarY.getProgress()));
    ArrayList<BarEntry> values = new ArrayList<>();
    for (int i = 0; i < seekBarX.getProgress(); i++) {
        float mul = (seekBarY.getProgress() + 1);
        float val1 = (float) (Math.random() * mul) + mul / 3;
        float val2 = (float) (Math.random() * mul) + mul / 3;
        float val3 = (float) (Math.random() * mul) + mul / 3;
        values.add(new BarEntry(i, new float[] { val1, val2, val3 }, getResources().getDrawable(R.drawable.star)));
    }
    BarDataSet set1;
    if (chart.getData() != null && chart.getData().getDataSetCount() > 0) {
        set1 = (BarDataSet) chart.getData().getDataSetByIndex(0);
        set1.setValues(values);
        chart.getData().notifyDataChanged();
        chart.notifyDataSetChanged();
    } else {
        set1 = new BarDataSet(values, "Statistics Vienna 2014");
        set1.setDrawIcons(false);
        set1.setColors(getColors());
        set1.setStackLabels(new String[] { "Births", "Divorces", "Marriages" });
        ArrayList<IBarDataSet> dataSets = new ArrayList<>();
        dataSets.add(set1);
        BarData data = new BarData(dataSets);
        data.setValueFormatter(new MyValueFormatter());
        data.setValueTextColor(Color.WHITE);
        chart.setData(data);
    }
    chart.setFitBars(true);
    chart.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)

Aggregations

BarData (com.github.mikephil.charting.data.BarData)1 BarDataSet (com.github.mikephil.charting.data.BarDataSet)1 BarEntry (com.github.mikephil.charting.data.BarEntry)1 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)1 MyValueFormatter (com.xxmassdeveloper.mpchartexample.custom.MyValueFormatter)1 ArrayList (java.util.ArrayList)1