我正在尝试使用hashmap中的值生成条形图。例如,状态中的城市的键 - 状态,值 - 数量。但是我得到了bardata的错误无法重新回到bardata(java arrsylist,bardataset)
BarChart barChart= (BarChart) findViewById(R.id.graph);
int k=0;
ArrayList<BarEntry> barEntries=new ArrayList<>();
ArrayList<String> theStates=new ArrayList<>();
for (Map.Entry<String, Integer> entry : h.entrySet()) {
barEntries.add(new BarEntry(entry.getValue(), k));
k++;
theStates.add(entry.getKey());
System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
BarDataSet barDataSet = new BarDataSet(barEntries,"CRIME");
BarData theData = new BarData(theStates, barDataSet);//error occurs here
barChart.setData(theData);
答案 0 :(得分:0)
使用XAxis值Formatter显示标签
BarDataSet barDataSet = new BarDataSet(barEntries,"CRIME");
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(barDataSet );
BarData data = new BarData(dataSets);
graph.setData(data);