我遇到data = new BarData(名称,yAxis)的问题;
无法解析构造函数' BarData(java.lang.String [],java.util.ArrayList)
我使用com.github.PhilJay:MPAndroidChart:v2.2.5
我是这种编程语言的新手,我正在写文凭,但我遇到了这样的问题,我需要在程序中插入图形,请帮忙。
private ProgressDialog pd;
ArrayList<BarDataSet> yAxis;
ArrayList<BarEntry> yValues;
ArrayList<String> xAxis1;
BarEntry values ;
BarChart chart;
BarData data;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.graph_temp);
pd = new ProgressDialog(intoGraph.this);
pd.setMessage("load");
// Log.d("array",Arrays.toString(fullData));
chart = (BarChart) findViewById(R.id.chart);
load_data_from_server();
}
public void load_data_from_server() {
pd.show();
String url = "http://192.168.0.3/temp2.php";
xAxis1 = new ArrayList<>();
yAxis = null;
yValues = new ArrayList<>();
StringRequest stringRequest = new StringRequest(Request.Method.POST,
url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("string",response);
try {
JSONArray jsonarray = new JSONArray(response);
for(int i=0; i < jsonarray.length(); i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i);
String temperature = jsonobject.getString("temperature").trim();
String date = jsonobject.getString("date").trim();
xAxis1.add(date);
values = new BarEntry(Float.valueOf(temperature),i);
yValues.add(values);
}
} catch (JSONException e) {
e.printStackTrace();
}
BarDataSet barDataSet1 = new BarDataSet(yValues, "temper");
barDataSet1.setColor(Color.rgb(0, 82, 159));
yAxis = new ArrayList<>();
yAxis.add(barDataSet1);
String names[]= xAxis1.toArray(new String[xAxis1.size()]);
data = new BarData(names, yAxis);
chart.setData(data);
chart.setDescription("");
chart.animateXY(2000, 2000);
chart.invalidate();
pd.hide();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if(error != null){
Toast.makeText(getApplicationContext(), "err...", Toast.LENGTH_LONG).show();
pd.hide();
}
}
}
);
MySingleton.getInstance(getApplicationContext()).addToRequestQueue(stringRequest);
}
}
答案 0 :(得分:0)
BarData构造函数为参数采用BarDataSet或多个BarDataSet。这是一个简化的例子:
List<BarEntry> entries = new ArrayList<>();
entries.add(new BarEntry(0f, 30f));
BarDataSet set = new BarDataSet(entries, "BarDataSet");
BarData data = new BarData(set);