Step1 Dividi il primo numero di gruppi nel grafico a barre. Come sotto il codice di esempio visualizzato per 5 gruppi. Ogni gruppo ha 5 barre in questo.
xaxis0 = new ArrayList<>();
for (int i = 0; i < cData.size(); i++) {
String str = cData.get(i).get("count");
str = str.replaceAll("\\[", "").replaceAll("\\]", "");
String[] finalString = str.split(",");
if (i == 0) {
for (int k = 0; k < finalString.length; k++) {
int data22 = Integer.parseInt(finalString[k]);
BarEntry v1e1 = new BarEntry(data22, position);
valueSet1.add(v1e1);
}
}
if (i == 1) {
for (int k = 0; k < finalString.length; k++) {
int data22 = Integer.parseInt(finalString[k] + "");
BarEntry v1e1 = new BarEntry(data22, position);
valueSet2.add(v1e1);
}
}
if (i == 2) {
for (int k = 0; k < finalString.length; k++) {
int data22 = Integer.parseInt(finalString[k] + "");
BarEntry v1e1 = new BarEntry(data22, position);
valueSet3.add(v1e1);
}
}
if (i == 3) {
for (int k = 0; k < finalString.length; k++) {
int data22 = Integer.parseInt(finalString[k] + "");
BarEntry v1e1 = new BarEntry(data22, position);
valueSet4.add(v1e1);
}
}
if (i == 4) {
for (int k = 0; k < finalString.length; k++) {
int data22 = Integer.parseInt(finalString[k] + "");
BarEntry v1e1 = new BarEntry(data22, position);
valueSet5.add(v1e1);
}
}
xaxis0.add(i, xdata.get(i).get("date"));
Step2 Nel codice di cui sopra si osserva che 5 gruppi di dati ingresso barra di caricamento in anello di ogni valueset - ArrayList valueSet2 = new ArrayList <>(); inizializzazione davanti a questo valuesets e
Fase 3 e di carico che 5 set a Bardataset come qui di seguito
`BarDataSet barDataSet1 = new BarDataSet (valueSet1, "Set1"); barDataSet1.setColors (whitecolors); barDataSet1.setValueTextColor (Color.WHITE);
BarDataSet barDataSet2 = nuovo BarDataSet (valueSet2, "Set2"); barDataSet2.setColors (whitecolors); barDataSet2.setValueTextColor (Color.WHITE);
BarDataSet barDataSet3 = nuovo BarDataSet (valueSet3, "Set3"); barDataSet3.setColors (whitecolors);
barDataSet3.setValueTextColor (Color.WHITE); BarDataSet barDataSet4 = new BarDataSet (valueSet4, "Set4");
barDataSet4.setColors (whitecolors); barDataSet4.setValueTextColor (Color.WHITE);
BarDataSet barDataSet5 = nuovo BarDataSet (valueSet5, "Set5"); barDataSet5.setColors (whitecolors);
barDataSet5.setValueTextColor (Color.WHITE); dataSets = new ArrayList <>(); dataSets.add (barDataSet1); dataSets.add (barDataSet2); dataSets.add (barDataSet3); dataSets.add (barDataSet4); dataSets.add (barDataSet5); `
Ultimo passo necessario allegata questi dati per Bardata come sottostante Codice
BarData data11 = new BarData (xaxis0, set di dati); data11.setGroupSpace (100f);
holder.chart.setData(data11);
XAxis xAxis = holder.chart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(true);
xAxis.setGridColor (context.getResources() getColor (R.color.white).);
xAxis.isDrawLabelsEnabled();
xAxis.setAxisLineColor (context.getResources() getColor (R.color.accentColor).); xAxis.setTextColor (context.getResources(). GetColor (R.color.white));
xAxis.isAdjustXLabelsEnabled();
xAxis.setAdjustXLabels(true);
holder.chart.setDescription("");
holder.chart.animateXY(2000, 2000);
holder.chart.getAxisLeft().setTextColor(context.getResources().getColor(R.color.white));
holder.chart.getAxisRight().setTextColor(context.getResources().getColor(R.color.white));
holder.chart.setDrawGridBackground(false);
holder.chart.getAxisRight().setEnabled(false);
holder.chart.setDrawValueAboveBar(true);
holder.chart.getAxisLeft().setEnabled(false);
holder.chart.setSoundEffectsEnabled(true);
holder.chart.getXAxis().setDrawGridLines(false);
holder.chart.setTransitionGroup(true);
YAxis yAxis = holder.chart.getAxisLeft();
yAxis.setDrawGridLines(false);
yAxis.setLabelCount(5);
yAxis = holder.chart.getAxisRight();
yAxis.setDrawGridLines(false);
yAxis.setTextColor(context.getResources().getColor(R.color.white));
Legend l = holder.chart.getLegend();
l.setEnabled(false);
Paint p = holder.chart.getPaint(Chart.PAINT_INFO);
p.setTextSize(10);
p.setColor(context.getResources().getColor(R.color.white));
p.setTypeface(gotham);
holder.chart.invalidate();
l.setPosition(Legend.LegendPosition.BELOW_CHART_CENTER);
l.setTextSize(200);
yAxis.setValueFormatter(new LargeValueFormatter());
# Thats it if you have doubt about this code ask me any time .......
fonte
2017-09-05 07:30:51
Phillipp il costruttore di BarData è cambiato! Devi aggiornare il tuo codice! – lidox