Android graphview x值低于以前的值

时间:2016-11-19 20:00:54

标签: android android-studio android-graphview

我想使用android GraphView库绘制x,y绘图,当我尝试这个系列时我得到了错误,请帮助为什么那个图表不能绘制 我的系列和代码如下:

double[] series1Numbers = {0.07, 0.066, 0.069, 0.077, 0.090, 0.106, 0.123, 0.142, 0.161, 0.180, 0.200 };
double[] series2Numbers = {0.08, 0.078, 0.094, 0.101, 0.108, 0.115, 0.122, 0.129, 0.136, 0.143, 0.150};

for (int i = 0; i < series1Numbers.length; i++){
    series.appendData(new DataPoint(series2Numbers[i], series1Numbers[i]), true, 20);
    Log.d("x,y : ", String.valueOf(series1Numbers[i]) + ", " + String.valueOf(series2Numbers[i]));
}

graph.addSeries(series);

这是我的错误:

11-20 02:56:45.285  18818-18818/com.example.fetimeh.timol E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.fetimeh.timol, PID: 18818
    java.lang.IllegalArgumentException: new x-value must be greater then the last value. x-values has to be ordered in ASC.
            at com.jjoe64.graphview.series.BaseSeries.appendData(BaseSeries.java:411)
            at com.jjoe64.graphview.series.LineGraphSeries.appendData(LineGraphSeries.java:646)
            at com.jjoe64.graphview.series.BaseSeries.appendData(BaseSeries.java:464)
            at com.example.fetimeh.timol.calc.tidakadakorelasi$1.onClick(tidakadakorelasi.java:126)
            at android.view.View.performClick(View.java:4757)
            at android.view.View$PerformClick.run(View.java:19757)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5219)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)

1 个答案:

答案 0 :(得分:0)

您无法向后追加数据。如果您需要更改过去的数据点,则必须重置完整数据。

对于此用途resetData而不是appendData。请注意,将所有值都作为参数,而不仅仅是新值。