use of com.github.mikephil.charting.data.BarData in project MPAndroidChart by PhilJay.
the class AnotherBarActivity 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 val = (float) (Math.random() * mult) + mult / 3;
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, "Data Set");
set1.setColors(ColorTemplate.VORDIPLOM_COLORS);
set1.setDrawValues(false);
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
BarData data = new BarData(dataSets);
mChart.setData(data);
mChart.setFitBars(true);
}
mChart.invalidate();
}
use of com.github.mikephil.charting.data.BarData in project MPAndroidChart by PhilJay.
the class BarChartActivityMultiDataset method onProgressChanged.
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
float groupSpace = 0.08f;
// x4 DataSet
float barSpace = 0.03f;
// x4 DataSet
float barWidth = 0.2f;
// (0.2 + 0.03) * 4 + 0.08 = 1.00 -> interval per "group"
int groupCount = mSeekBarX.getProgress() + 1;
int startYear = 1980;
int endYear = startYear + groupCount;
tvX.setText(startYear + "-" + endYear);
tvY.setText("" + (mSeekBarY.getProgress()));
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
ArrayList<BarEntry> yVals2 = new ArrayList<BarEntry>();
ArrayList<BarEntry> yVals3 = new ArrayList<BarEntry>();
ArrayList<BarEntry> yVals4 = new ArrayList<BarEntry>();
float randomMultiplier = mSeekBarY.getProgress() * 100000f;
for (int i = startYear; i < endYear; i++) {
yVals1.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
yVals2.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
yVals3.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
yVals4.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
}
BarDataSet set1, set2, set3, set4;
if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
set1 = (BarDataSet) mChart.getData().getDataSetByIndex(0);
set2 = (BarDataSet) mChart.getData().getDataSetByIndex(1);
set3 = (BarDataSet) mChart.getData().getDataSetByIndex(2);
set4 = (BarDataSet) mChart.getData().getDataSetByIndex(3);
set1.setValues(yVals1);
set2.setValues(yVals2);
set3.setValues(yVals3);
set4.setValues(yVals4);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
} else {
// create 4 DataSets
set1 = new BarDataSet(yVals1, "Company A");
set1.setColor(Color.rgb(104, 241, 175));
set2 = new BarDataSet(yVals2, "Company B");
set2.setColor(Color.rgb(164, 228, 251));
set3 = new BarDataSet(yVals3, "Company C");
set3.setColor(Color.rgb(242, 247, 158));
set4 = new BarDataSet(yVals4, "Company D");
set4.setColor(Color.rgb(255, 102, 0));
BarData data = new BarData(set1, set2, set3, set4);
data.setValueFormatter(new LargeValueFormatter());
data.setValueTypeface(mTfLight);
mChart.setData(data);
}
// specify the width each bar should have
mChart.getBarData().setBarWidth(barWidth);
// restrict the x-axis range
mChart.getXAxis().setAxisMinimum(startYear);
// barData.getGroupWith(...) is a helper that calculates the width each group needs based on the provided parameters
mChart.getXAxis().setAxisMaximum(startYear + mChart.getBarData().getGroupWidth(groupSpace, barSpace) * groupCount);
mChart.groupBars(startYear, groupSpace, barSpace);
mChart.invalidate();
}
use of com.github.mikephil.charting.data.BarData in project MPAndroidChart by PhilJay.
the class BarChartActivitySinus method setData.
private void setData(int count) {
ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
for (int i = 0; i < count; i++) {
entries.add(mSinusData.get(i));
}
BarDataSet set;
if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
set = (BarDataSet) mChart.getData().getDataSetByIndex(0);
set.setValues(entries);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
} else {
set = new BarDataSet(entries, "Sinus Function");
set.setColor(Color.rgb(240, 120, 124));
}
BarData data = new BarData(set);
data.setValueTextSize(10f);
data.setValueTypeface(mTfLight);
data.setDrawValues(false);
data.setBarWidth(0.8f);
mChart.setData(data);
}
use of com.github.mikephil.charting.data.BarData in project MPAndroidChart by PhilJay.
the class RealmDatabaseActivityBar method setData.
private void setData() {
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
//RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
// stacked entries
RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "xValue", "yValue");
set.setColors(new int[] { ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4") });
set.setLabel("Realm BarDataSet");
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
// add the dataset
dataSets.add(set);
// create a data object with the dataset list
BarData data = new BarData(dataSets);
styleData(data);
// set data
mChart.setData(data);
mChart.setFitBars(true);
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
use of com.github.mikephil.charting.data.BarData in project MPAndroidChart by PhilJay.
the class ListViewBarChartActivity method generateData.
/**
* generates a random ChartData object with just one DataSet
*
* @return
*/
private BarData generateData(int cnt) {
ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
for (int i = 0; i < 12; i++) {
entries.add(new BarEntry(i, (float) (Math.random() * 70) + 30));
}
BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
d.setColors(ColorTemplate.VORDIPLOM_COLORS);
d.setBarShadowColor(Color.rgb(203, 203, 203));
ArrayList<IBarDataSet> sets = new ArrayList<IBarDataSet>();
sets.add(d);
BarData cd = new BarData(sets);
cd.setBarWidth(0.9f);
return cd;
}
Aggregations