use of com.github.mikephil.charting.data.BarData in project MPAndroidChart by PhilJay.
the class ListViewBarChartActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_listview_chart);
ListView lv = (ListView) findViewById(R.id.listView1);
ArrayList<BarData> list = new ArrayList<BarData>();
// 20 items
for (int i = 0; i < 20; i++) {
list.add(generateData(i + 1));
}
ChartDataAdapter cda = new ChartDataAdapter(getApplicationContext(), list);
lv.setAdapter(cda);
}
use of com.github.mikephil.charting.data.BarData in project MPAndroidChart by PhilJay.
the class ListViewMultiChartActivity method generateDataBar.
/**
* generates a random ChartData object with just one DataSet
*
* @return
*/
private BarData generateDataBar(int cnt) {
ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
for (int i = 0; i < 12; i++) {
entries.add(new BarEntry(i, (int) (Math.random() * 70) + 30));
}
BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
d.setColors(ColorTemplate.VORDIPLOM_COLORS);
d.setHighLightAlpha(255);
BarData cd = new BarData(d);
cd.setBarWidth(0.9f);
return cd;
}
use of com.github.mikephil.charting.data.BarData in project MPAndroidChart by PhilJay.
the class StackedBarActivityNegative method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_age_distribution);
setTitle("Age Distribution Austria");
mChart = (HorizontalBarChart) findViewById(R.id.chart1);
mChart.setOnChartValueSelectedListener(this);
mChart.setDrawGridBackground(false);
mChart.getDescription().setEnabled(false);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
mChart.setDrawBarShadow(false);
mChart.setDrawValueAboveBar(true);
mChart.setHighlightFullBarEnabled(false);
mChart.getAxisLeft().setEnabled(false);
mChart.getAxisRight().setAxisMaximum(25f);
mChart.getAxisRight().setAxisMinimum(-25f);
mChart.getAxisRight().setDrawGridLines(false);
mChart.getAxisRight().setDrawZeroLine(true);
mChart.getAxisRight().setLabelCount(7, false);
mChart.getAxisRight().setValueFormatter(new CustomFormatter());
mChart.getAxisRight().setTextSize(9f);
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTH_SIDED);
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(false);
xAxis.setTextSize(9f);
xAxis.setAxisMinimum(0f);
xAxis.setAxisMaximum(110f);
xAxis.setCenterAxisLabels(true);
xAxis.setLabelCount(12);
xAxis.setGranularity(10f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
private DecimalFormat format = new DecimalFormat("###");
@Override
public String getFormattedValue(float value, AxisBase axis) {
return format.format(value) + "-" + format.format(value + 10);
}
});
Legend l = mChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setFormSize(8f);
l.setFormToTextSpace(4f);
l.setXEntrySpace(6f);
// IMPORTANT: When using negative values in stacked bars, always make sure the negative values are in the array first
ArrayList<BarEntry> yValues = new ArrayList<BarEntry>();
yValues.add(new BarEntry(5, new float[] { -10, 10 }));
yValues.add(new BarEntry(15, new float[] { -12, 13 }));
yValues.add(new BarEntry(25, new float[] { -15, 15 }));
yValues.add(new BarEntry(35, new float[] { -17, 17 }));
yValues.add(new BarEntry(45, new float[] { -19, 20 }));
yValues.add(new BarEntry(45, new float[] { -19, 20 }, getResources().getDrawable(R.drawable.star)));
yValues.add(new BarEntry(55, new float[] { -19, 19 }));
yValues.add(new BarEntry(65, new float[] { -16, 16 }));
yValues.add(new BarEntry(75, new float[] { -13, 14 }));
yValues.add(new BarEntry(85, new float[] { -10, 11 }));
yValues.add(new BarEntry(95, new float[] { -5, 6 }));
yValues.add(new BarEntry(105, new float[] { -1, 2 }));
BarDataSet set = new BarDataSet(yValues, "Age Distribution");
set.setDrawIcons(false);
set.setValueFormatter(new CustomFormatter());
set.setValueTextSize(7f);
set.setAxisDependency(YAxis.AxisDependency.RIGHT);
set.setColors(new int[] { Color.rgb(67, 67, 72), Color.rgb(124, 181, 236) });
set.setStackLabels(new String[] { "Men", "Women" });
String[] xLabels = new String[] { "0-10", "10-20", "20-30", "30-40", "40-50", "50-60", "60-70", "70-80", "80-90", "90-100", "100+" };
BarData data = new BarData(set);
data.setBarWidth(8.5f);
mChart.setData(data);
mChart.invalidate();
}
use of com.github.mikephil.charting.data.BarData in project MPAndroidChart by PhilJay.
the class RealmDatabaseActivityHorizontalBar 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", "stackValues", "floatValue");
set.setColors(new int[] { ColorTemplate.rgb("#8BC34A"), ColorTemplate.rgb("#FFC107"), ColorTemplate.rgb("#9E9E9E") });
set.setLabel("Mobile OS distribution");
set.setStackLabels(new String[] { "iOS", "Android", "Other" });
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);
data.setValueTextColor(Color.WHITE);
// set data
mChart.setData(data);
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
use of com.github.mikephil.charting.data.BarData in project MPAndroidChart by PhilJay.
the class RealmWikiExample method setData.
private void setData() {
// LINE-CHART
final RealmResults<Score> results = mRealm.where(Score.class).findAll();
IAxisValueFormatter formatter = new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return results.get((int) value).getPlayerName();
}
};
lineChart.getXAxis().setValueFormatter(formatter);
barChart.getXAxis().setValueFormatter(formatter);
RealmLineDataSet<Score> lineDataSet = new RealmLineDataSet<Score>(results, "scoreNr", "totalScore");
lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
lineDataSet.setLabel("Result Scores");
lineDataSet.setDrawCircleHole(false);
lineDataSet.setColor(ColorTemplate.rgb("#FF5722"));
lineDataSet.setCircleColor(ColorTemplate.rgb("#FF5722"));
lineDataSet.setLineWidth(1.8f);
lineDataSet.setCircleRadius(3.6f);
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
dataSets.add(lineDataSet);
LineData lineData = new LineData(dataSets);
styleData(lineData);
// set data
lineChart.setData(lineData);
lineChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
// BAR-CHART
RealmBarDataSet<Score> barDataSet = new RealmBarDataSet<Score>(results, "scoreNr", "totalScore");
barDataSet.setColors(new int[] { ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4") });
barDataSet.setLabel("Realm BarDataSet");
ArrayList<IBarDataSet> barDataSets = new ArrayList<IBarDataSet>();
barDataSets.add(barDataSet);
BarData barData = new BarData(barDataSets);
styleData(barData);
barChart.setData(barData);
barChart.setFitBars(true);
barChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
Aggregations