简体   繁体   中英

How to display 4 co-ordinate GraphView in android

i get error at

    GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
        new GraphViewData(1, 2.0d)
        , new GraphViewData(2, -1.5d)
        , new GraphViewData(-3, 2.5d)
        , new GraphViewData(-4, -1.0d)
    });

    GraphView graphView = new LineGraphView(
        this // context
        , "GraphView" // heading
    );
    graphView.addSeries(exampleSeries); // data
    graphView.getGraphViewStyle().setNumHorizontalLabels(5);
    graphView.getGraphViewStyle().setNumVerticalLabels(5);
    //graphView.getGraphViewStyle().setVerticalLabelsWidth(300);
    graphView.setManualYAxisBounds(5,1);


    LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
    layout.addView(graphView);

I want to draw the line for all four co-ordinates.. but the negative points does not work.. help me

iwant like this

stack trace

09-01 04:17:53.299: I/Process(2263): Sending signal. PID: 2263 SIG: 9
09-01 04:17:54.149: D/AndroidRuntime(2302): Shutting down VM
09-01 04:17:54.149: W/dalvikvm(2302): threadid=1: thread exiting with uncaught exception (group=0xb3afcba8)
09-01 04:17:54.169: E/AndroidRuntime(2302): FATAL EXCEPTION: main
09-01 04:17:54.169: E/AndroidRuntime(2302): Process: com.jsk.simplegraph, PID: 2302
09-01 04:17:54.169: E/AndroidRuntime(2302): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jsk.simplegraph/com.jsk.simplegraph.SimpleGraphMainActivity}: 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.
09-01 04:17:54.169: E/AndroidRuntime(2302):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
09-01 04:17:54.169: E/AndroidRuntime(2302):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
09-01 04:17:54.169: E/AndroidRuntime(2302):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
09-01 04:17:54.169: E/AndroidRuntime(2302):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
09-01 04:17:54.169: E/AndroidRuntime(2302):     at android.os.Handler.dispatchMessage(Handler.java:102)
09-01 04:17:54.169: E/AndroidRuntime(2302):     at android.os.Looper.loop(Looper.java:136)
09-01 04:17:54.169: E/AndroidRuntime(2302):     at android.app.ActivityThread.main(ActivityThread.java:5017)
09-01 04:17:54.169: E/AndroidRuntime(2302):     at java.lang.reflect.Method.invokeNative(Native Method)
09-01 04:17:54.169: E/AndroidRuntime(2302):     at java.lang.reflect.Method.invoke(Method.java:515)
09-01 04:17:54.169: E/AndroidRuntime(2302):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-01 04:17:54.169: E/AndroidRuntime(2302):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-01 04:17:54.169: E/AndroidRuntime(2302):     at dalvik.system.NativeStart.main(Native Method)
09-01 04:17:54.169: E/AndroidRuntime(2302): Caused by: 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.
09-01 04:17:54.169: E/AndroidRuntime(2302):     at com.jjoe64.graphview.GraphViewSeries.checkValueOrder(GraphViewSeries.java:200)
09-01 04:17:54.169: E/AndroidRuntime(2302):     at com.jjoe64.graphview.GraphViewSeries.<init>(GraphViewSeries.java:74)

read the stacktrace

09-01 04:17:54.169: E/AndroidRuntime(2302): Caused by: 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.

try this

GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
    new GraphViewData(-4, -1.0d),
    new GraphViewData(-3, 2.5d),
    new GraphViewData(2, -1.5d),
    new GraphViewData(1, 2.0d)
});

Your stack message is quite clear:

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.

So, you should initialize exampleSeries the following way:

GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
    new GraphViewData(-4, -1.0d),
    new GraphViewData(-3, 2.5d),
    new GraphViewData(1, 2.0d),
    new GraphViewData(2, -1.5d)
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM