1

I am getting the following exception

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$2.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)

when using this code:

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;
}

The order of the values is not correct. making linear graphview in android says the xaxis needs to be sorted, how to display the true values without sorting?

Saad Malhas
  • 19
  • 1
  • 10

1 Answers1

1

In DataPoint first comes the X value and then comes the Y value. But you do it the other way. Here is how it should be:

DataPoint v = new DataPoint(i, Double.parseDouble(ethPrice.get(i)));
Psytho
  • 3,313
  • 2
  • 19
  • 27