请帮助我使用mpandroidchartlibrary-2-2-4生成组合线条和条形图的代码。
请找到代码
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
可以设置标签
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;
}
}
当我运行此代码时,只有“4和5”标签以相反的顺序显示在图表上。无法看到剩余的标签
答案 0 :(得分:1)