MPAndroidChart 未更新
2022-09-04 05:12:54
我有一个这样的哈希图
LinkedHashMap<String, String> hash = new LinkedHashMap<>();
hash.put("2015-05-03", 100);
hash.put("2015-05-04", 110);
hash.put("2015-05-05", 90);
hash.put("2015-05-06", 40);
我想通过MPAndroidChart设计一个线图,但它不起作用,图表无效,没有什么可显示的!似乎我的代码是无效的。
这是我的代码:
private void setChartData(LinkedHashMap<String, String> lastMonthMediaLikes)
{
ArrayList<String> xVals = new ArrayList<>();
for(Map.Entry<String, String> entry : lastMonthMediaLikes.entrySet())
{
xVals.add(entry.getKey());
}
ArrayList<Entry> vals1 = new ArrayList<>();
int i = 0;
for(Map.Entry<String, String> entry : lastMonthMediaLikes.entrySet())
{
vals1.add(new Entry(Float.valueOf(entry.getValue()), i));
i++;
}
// create a dataset and give it a type
LineDataSet set1 = new LineDataSet(vals1, "DataSet 1");
set1.setDrawCubic(true);
set1.setCubicIntensity(0.2f);
//set1.setDrawFilled(true);
set1.setDrawCircles(false);
set1.setLineWidth(1.8f);
set1.setCircleSize(4f);
set1.setCircleColor(Color.WHITE);
set1.setHighLightColor(Color.rgb(244, 117, 117));
set1.setColor(Color.WHITE);
set1.setFillColor(Color.WHITE);
set1.setFillAlpha(100);
set1.setDrawHorizontalHighlightIndicator(false);
set1.setFillFormatter(new FillFormatter()
{
@Override
public float getFillLinePosition(LineDataSet dataSet, LineDataProvider dataProvider)
{
return -10;
}
});
// create a data object with the datasets
LineData data = new LineData(xVals, set1);
//data.setValueTypeface(tf);
data.setValueTextSize(9f);
data.setDrawValues(false);
// set data
chart.setData(data);
}
请指教,我该怎么办?