2016-07-12 36 views
-1

繪製圖形我想繪製MPAndroidChart折線圖,但是當我要定線數據我得到這個錯誤:使用Mpandroid圖表

LineData (com.github.mikephil.charting.interfaces.datasets.ILineDataSet...) in LineData cannot be applied to (java.util.ArrayList, com.github.mikephil.charting.data.LineDataSet)

a picture of the error message in IDE

回答

0

目前,沒有構造函數,接受List<string>,LineDataSet。可用的構造函數爲:

public LineData() { 
    super(); 
} 

public LineData(ILineDataSet... dataSets) { 
    super(dataSets); 
} 

public LineData(List<ILineDataSet> dataSets) { 
    super(dataSets); 
} 

您可以閱讀整個班級定義here

您需要以不同的方式設置x值。 This示例可能會對您有所幫助。

-1
XAxis xAxis = lineChart.getXAxis(); 
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); 
xAxis.setDrawGridLines(true); 
xAxis.setDrawAxisLine(true); 
xAxis.setTextSize(10f); 
date.clear(); 
for (int i = 0; i < size; i++) { 
    date.add("第" + i + "天"); 


} 
//Set the X axis below the data (not the same as the previous version) 

xAxis.setValueFormatter(new AxisValueFormatter() { 
    @Override 
    public String getFormattedValue(float value, AxisBase axis) { 
     axis.setGranularityEnabled(true); 
     axis.resetAxisMaxValue(); 
     axis.isAxisMaxCustom(); 
     int a = (int) value; 

     return date.get(a);// Data below 
    } 

    @Override 
    public int getDecimalDigits() { 
     return 0; 
    } 
}); 

也許它會幫助你

+0

請你的答案 – Naga2Raja

+0

即使翻譯代碼註釋爲英語將是一個巨大的幫助很少提供更多的解釋。 – Laurel

相關問題