使用Mpandroid图表绘制图形

时间:2016-07-12 18:49:03

标签: java android mpandroidchart

我想用MPAndroidChart绘制折线图,​​但是当我想设置行数据时,我收到此错误:

  LineData中的LineData(com.github.mikephil.charting.interfaces.datasets.ILineDataSet ...)无法应用于   (java.util.ArrayList,com.github.mikephil.charting.data.LineDataSet)

a picture of the error message in IDE

2 个答案:

答案 0 :(得分:0)

目前,没有接受List<string>LineDataSet的构造函数。可用的构造函数是:

public LineData() {
    super();
}

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

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

您可以阅读整个班级定义here

您需要以不同方式设置x值。 This示例可能会对您有所帮助。

答案 1 :(得分:-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;
    }
});

也许它会帮助你

相关问题