gpt4 book ai didi

java - 无法解析构造函数 'BarEntry(java.lang.String, java.lang.Float)

转载 作者:行者123 更新时间:2023-12-04 09:03:43 25 4
gpt4 key购买 nike

我想从下面的 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"}]
该数据是从数据库到我的图表,但我收到了上面的错误
我插入全文的代码如下
      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 应该是这个月,我怎么能做到这一点?

最佳答案

A constructor in Java is a special method that is used to initialiseobjects. The constructor is called when an object of a class iscreated.

import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
查询 BarEntry 类(class)。
/**
* Constructor for normal bars (not stacked).
*
* @param x
* @param y
*/
public BarEntry(float x, float y) {
super(x, y);
}


public BarEntry(float x, float y, Object data) {
super(x, y, data);
}


public BarEntry(float x, float y, Drawable icon) {
super(x, y, icon);
}


public BarEntry(float x, float y, Drawable icon, Object data) {
super(x, y, icon, data);
}


public BarEntry(float x, float[] vals) {
super(x, calcSum(vals));

this.mYVals = vals;

}


public BarEntry(float x, float[] vals, Object data) {
super(x, calcSum(vals), data);

this.mYVals = vals;

}


public BarEntry(float x, float[] vals, Drawable icon) {
super(x, calcSum(vals), icon);

this.mYVals = vals;

}


public BarEntry(float x, float[] vals, Drawable icon, Object data) {
super(x, calcSum(vals), icon, data);

this.mYVals = vals;

}
演示
 ArrayList<BarEntry> barEntries = new ArrayList<>();

barEntries.add(new BarEntry(1f, 0));
barEntries.add(new BarEntry(2f, 1));

关于java - 无法解析构造函数 'BarEntry(java.lang.String, java.lang.Float),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63505219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com