线性 graphView 没有排序 arraylist

linear graphView without sorting arraylist

我收到以下异常

04-30 09:51:09.203 30599-30599/com.example.saadm.bitcoinwatcher E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.saadm.bitcoinwatcher, PID: 30599
java.lang.IllegalArgumentException: The order of the values is not correct. X-Values have to be ordered ASC. First the lowest x value and at least the highest x value.
    at com.jjoe64.graphview.series.BaseSeries.checkValueOrder(BaseSeries.java:532)
    at com.jjoe64.graphview.series.BaseSeries.<init>(BaseSeries.java:117)
    at com.jjoe64.graphview.series.LineGraphSeries.<init>(LineGraphSeries.java:163)
    at com.example.saadm.bitcoinwatcher.MainActivity.onClick(MainActivity.java:79)
    at android.view.View.performClick(View.java:6256)
    at android.view.View$PerformClick.run(View.java:24701)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

使用此代码时:

priceEth.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ArrayList<String> newar = new ArrayList<>();
                    newar = ethPrice;
                    //Collections.sort(ethPrice);
                    LineGraphSeries<DataPoint> ser = new LineGraphSeries<>(dats());
                    ethPrice = newar;
                    graph.addSeries(ser);

                }
            });

 private DataPoint[] dats() {
            int n = ethPrice.size();
            DataPoint[] values = new DataPoint[n];

            for(int i = 0; i<n;i++){

                DataPoint v = new DataPoint(Double.parseDouble(ethPrice.get(i)), i);
                values[i]=v;
            }
            return values;
}

值的顺序不正确。 making linear graphview in android 说xaxis需要排序,如何在不排序的情况下显示真实值?

DataPoint中首先是X值,然后是Y值。但是你用另一种方式来做。应该是这样的:

DataPoint v = new DataPoint(i, Double.parseDouble(ethPrice.get(i)));