Reputation: 23
Please help me with the code for generating a combined Line and bar graph with mpandroidchartlibrary-2-2-4.
Please find the Code
main.java
for (int win = 0; win < sprintArray.length; win++) {
labels.add(win, window_List.get(win));
System.out.println("WINDOW LIST VALUE IN CHART" + window_List.get(win).toString());
}
for (int window = 0; window < sprintArray.length; window++) {
float wc_entry = Float.parseFloat(workcompleted_list.get(window).toString());
float wr_entry = Float.parseFloat(workremaining_list.get(window).toString());
float wa_entry = Float.parseFloat(workadded_List.get(window).toString());
System.out.println("WC VALUE"+workcompleted_list);
System.out.println("WR VALUE"+workremaining_list);
System.out.println("WA VALUE"+workadded_List);
wc_group.add(new BarEntry(window+3,wc_entry));
wr_group.add(new BarEntry(window+3,wr_entry));
wa_group.add(new BarEntry(window+3,wa_entry));
}
BarDataSet barDataSet1 = new BarDataSet(wc_group, "Work Completed");
barDataSet1.setColor(Color.rgb(217, 227, 184));
barDataSet1.setDrawValues(false);
BarDataSet barDataSet2 = new BarDataSet(wr_group, "Work Remaining");
barDataSet2.setColor(Color.rgb(107, 161, 202));
barDataSet2.setDrawValues(false);
BarDataSet barDataSet3 = new BarDataSet(wa_group, "Work Added");
barDataSet3.setColor(Color.rgb(77, 124, 159));
barDataSet3.setDrawValues(false);
final BarData data = new BarData(barDataSet1);
data.addDataSet(barDataSet2);
data.addDataSet(barDataSet3);
data.setBarWidth(0.45f);
barChart.setData(data);
barChart.setNoDataText("No Data Found!!!");
barChart.setNoDataTextColor(Color.YELLOW);
barChart.setFitBars(true);
barChart.animateY(2000);
barChart.setDrawGridBackground(false);
barChart.setDrawBorders(true);
barChart.getAxisRight().setEnabled(false);
barChart.setDescription(null);
barChart.getAxisLeft().setStartAtZero(true);
barChart.setVisibleXRange(2,10);
barChart.getAxisRight().setStartAtZero(true);
barChart.groupBars(2,0.72f,0.04f);
XAxis xAxis = barChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setTextSize(8);
barChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(labels)); //labels list have values "original estimate,1,2,3,4,5"
xAxis.setLabelCount(labels.size());
xAxis.setDrawGridLines(false);
xAxis.setAxisLineColor(Color.BLACK);
xAxis.setAxisLineColor(Color.rgb(255, 51, 153));
barChart.setDrawValueAboveBar(false);
YAxis yAxis = barChart.getAxisLeft();
yAxis.setDrawAxisLine(false);
yAxis.setDrawGridLines(false);
yAxis.setLabelCount(5);
}
IndexAxisValueFormatter.java
this is uded to set the labels
public class IndexAxisValueFormatter implements IAxisValueFormatter {
private String[] mValues = new String[] {};
private int mValueCount = 0;
@Override
public String getFormattedValue(float value, AxisBase axis) {
int index = Math.round(value);
if (index < 0 || index >= mValueCount || index != (int)value)
return "";
return mValues[index];
}
public IndexAxisValueFormatter() {
}
public IndexAxisValueFormatter(String[] values) {
if (values != null)
setValues(values);
}
public IndexAxisValueFormatter(Collection<String> values) {
if (values != null)
setValues(values.toArray(new String[values.size()]));
}
public String[] getValues()
{
return mValues;
}
public void setValues(String[] values)
{
if (values == null)
values = new String[] {};
this.mValues = values;
this.mValueCount = values.length;
}
}
When i run this code only "4 and 5 " labels are displayed on the chart in reverse order. cannot see remaining labels
Upvotes: 0
Views: 57
Reputation: 91
Why You don't use v3.0.2? Visit this link, there is example how to do combined chart.
Upvotes: 1