這就是所謂的「堆積條形圖」,它是可能在MPAndroidChart中。
有由下面的代碼生成在Github上回購爲例活動爲MPAndroidChart here:
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
for (int i = 0; i < size + 1; i++) {
float mult = (size + 1);
float val1 = (float) (Math.random() * mult) + mult/3;
float val2 = (float) (Math.random() * mult) + mult/3;
float val3 = (float) (Math.random() * mult) + mult/3;
yVals1.add(new BarEntry(
i,
new float[]{val1, val2, val3},
getResources().getDrawable(R.drawable.star)));
}
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, "Statistics Vienna 2014");
set1.setDrawIcons(false);
set1.setColors(getColors());
set1.setStackLabels(new String[]{"Births", "Divorces", "Marriages"});
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
BarData data = new BarData(dataSets);
data.setValueFormatter(new MyValueFormatter());
data.setValueTextColor(Color.WHITE);
mChart.setData(data);
}
mChart.setFitBars(true);
mChart.invalidate();
和輸出是這樣的:
你能描述data.setValueFormatter(新的MyValueFormatter())的細節;詳細 – Teekam
@Teekam它在GitHub repo中:https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/custom/MyValueFormatter.java –
HI Daviid得到了解決方案,謝謝。還有一個想法是在我的圖表中,酒吧價值顯示在每個酒吧的頂部,我希望它會顯示爲mpandroid圖表示例圖表。 – Teekam