我想从下面的json数据创建一个agraph
[{"month":"August 2020","total":"4587175.08"},{"month":"July 2020","total":"9151128.27"},{"month":"June 2020","total":"10859553.16"},{"month":"May 2020","total":"2600435.33"}]
这些数据是从db到我的图形的,但是我在插入entires的代码上面得到的错误如下
public void onResponse(@NotNull Call<List<MonthlySales>> call, @NotNull Response<List<MonthlySales>> response) {
//check if the response body is null
if(response.body()!=null){
List<BarEntry> barEntries = new ArrayList<>();
for (MonthlySales monthlySales : response.body()) {
barEntries.add(new BarEntry(monthlySales.getMonth(),monthlySales.getTotal()));
}
BarDataSet dataSet = new BarDataSet(barEntries,"Monthly Sales");
dataSet.setColors(ColorTemplate.MATERIAL_COLORS);
BarData data = new BarData(dataSet);
data.setBarWidth(10f);
chart.setVisibility(View.VISIBLE);
chart.animateXY(2000, 2000);
chart.setData(data);
chart.setFitBars(true);
Description description = new Description();
description.setText("Sales per month");
chart.setDescription(description);
chart.invalidate();
我会做错什么?请注意,月份应该是xaxis标签,而总数应该是yaxis标签,如何实现这一点?
1条答案
按热度按时间ezykj2lf1#
java中的构造函数是一种用于初始化对象的特殊方法。在创建类的对象时调用构造函数。
检查
BarEntry
班级。演示