Menu

How to clear existed series data properly?

tvhnet
2012-06-27
2012-07-05
  • tvhnet

    tvhnet - 2012-06-27

    I tried to use function setPoints in Series class as below:

    sr.setPoints(new Point[] {}, true);
    

    but it generated an exception:

    com.google.gwt.core.client.JavaScriptException: (TypeError): Unable to get value of the property 'x': object is null or undefined
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:248)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:289)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
        at org.moxieapps.gwt.highcharts.client.Series.nativeSetData(Series.java)
        at org.moxieapps.gwt.highcharts.client.Series.setPoints(Series.java:720)
    

    now, I have to build a native funtion like below:

    clearData(sr.getNativeSeries());
    private native void clearData(JavaScriptObject series) /*-{ series.data = []; }-*/;
    

    Does it invoke chart.redraw() automatically?

    Is there any better way?

    Thanks in advance!

     
  • Shawn Quinn

    Shawn Quinn - 2012-07-05

    Setting the points of the series to an empty array should be the correct way to clear a series. Note that you can also remove a series completely from the chart if you'd like via "Chart.removeSeries(...) .

    I tried the following and didn't run into any exceptions. There were some bug fixes in this area of the code over the past couple of releases though. Are you running the latest?

        final Chart chart = new Chart();
    
        final XAxis xAxis = chart.getXAxis()
            .setCategories("Apples", "Oranges", "Pears", "Grapes", "Bananas");
    
        final Series series = chart.createSeries()
            .setName("John")
            .setPoints(new Number[]{5, 3, 4, 7, 2});
        chart.addSeries(series);
        chart.addSeries(chart.createSeries()
            .setName("Jane")
            .setPoints(new Number[]{2, 2, 3, 2, 1})
        );
    
        chart.setClickEventHandler(new ChartClickEventHandler() {
            public boolean onClick(ChartClickEvent chartClickEvent) {
                series.setPoints(new Point[0]);
                return true;
            }
        });
    

    If you are running the latest, can you boil your scenario down to a simple use case and post it here so we can determine if there's a bug?

     

Log in to post a comment.