1
我想做折線圖,但我有問題要顯示xAxis中的值字符串,我使用庫Github從MPAndroidChart LineChart。請幫我如何添加字符串值,實際上對很多問題,我想問問如何在MPAndroidChart中設置xAxis的字符串值?
private void drawLineChartLine(){
private float[] yDataL = {40, 60, 70, 80};
private String[] xDataL = {"Week 1", "Week 1" , "Week 3" , "Week 4"};
ArrayList<Entry> yEntrys = new ArrayList<>();
final ArrayList<String> xEntrys = new ArrayList<>();
for(int i = 0; i < yDataL.length; i++){
yEntrys.add(new Entry(yDataL[i] ,i));
}
for(int i = 1; i < xDataL.length; i++){
xEntrys.add(xDataL[i]);
}
//create the data set
LineDataSet lineDataset = new LineDataSet(yEntrys, "assa");
XAxis xAxis = lineChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return xEntrys.get((int) value);
}
});
LineData lineData = new LineData(lineDataset);
lineChart.setData(lineData);
lineChart.invalidate();
}
我得到錯誤
在代碼無效的指數40,大小爲6
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return xEntrys.get((int) value);
}
});