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();
}
Aggregations