Ciortea Razvan
Lurker
I try to create a Bar Graph using JSON data. The problem is when try to save a specific data in an Entry object, with the mention that i save each value in a ArrayList for iteration needed to put each value as an Entry in the graph(Y AXIS).
This is the request and plot of the graph part:
And this is the result :
This is the request and plot of the graph part:
Java:
try {
JSONObject jsonObject = new JSONObject(response);
JSONObject open = jsonObject.getJSONObject("open");
for (int i = 0; i < open.length(); i++) {
int mon = open.getInt("hour");
int tue = open.getInt("day");
int wen = open.getInt("week");
int thu = open.getInt("month");
int fri = open.getInt("month_3");
int sat = open.getInt("month_6");
int sun = open.getInt("year");
// dates = new ArrayList<>();
// dates.add("Mon");
// dates.add("Tue");
// dates.add("Wen"); THIS IS THE ARRAY FOR THE X VALUES
// dates.add("Thu");
// dates.add("Fri");
// dates.add("Sat");
// dates.add("Sun");
xAxis1.add(dates.indexOf(0));
valoriAxaY.add(mon);
valoriAxaY.add(tue);
valoriAxaY.add(wen);
valoriAxaY.add(thu); // THIS IS THE ARRAY FOR THE Y VALUES
valoriAxaY.add(fri);
valoriAxaY.add(sat);
valoriAxaY.add(sun);
values = new BarEntry(valoriAxaY.indexOf(i), i); //THIS IS WHERE THE PROBLEM APPEARS
// ALSO I NEED TO MENTION THAT I GET NO ERROR'S
yValues.add(values);
}
} catch (Exception e) {
e.printStackTrace();
}
BarDataSet barDataSet = new BarDataSet(yValues, "Prices");
yAxis = new ArrayList<>();
yAxis.add(barDataSet);
data = new BarData(dates, yAxis);
barChart.setData(data);
barDataSet.setColors(ColorTemplate.VORDIPLOM_COLORS);
barChart.setDescription("CryptoCurrency");
barChart.invalidate();
}
And this is the result :
Attachments
Last edited: