Menu

setRedrawEventhandler

2012-06-25
2012-07-05
  • Robert Light

    Robert Light - 2012-06-25

    I was hoping you could point me in the right direction.

    I want to plot a series of "events" which happen at specific times on the same chart as some timeseries.

    In order to do this, I create a series which has the lineWidth set to 0 so that only the markers are displayed. Unfortunately, I have to set the "Y-axis" value to some value which will be at the bottom (or top) of the range being displayed.

    To get the display range, I create a RedrawEventHandler.

    I want to have the markers line up at the bottom of the graph (and hence my need to add the series when the graph is redrawn and I know what the y-axis min/max are at the time.

    when I add the following

        myChart.setRedrawEventHandler(new ChartRedrawEventHandler() {
            public boolean onRedraw(ChartRedrawEvent chartRedrawEvent) {
                Series myTickSeries = c.createSeries();    //TODO;  get rid of the old tickseries if one exists
                myTickSeries.setName("random event A");
                myTickSeries.addPoint( new Point(c.getXAxis().getExtremes().getMin(), c.getYAxis().getExtremes().getMin()));
                myTickSeries.addPoint( new Point(c.getXAxis().getExtremes().getMax(), c.getYAxis().getExtremes().getMin()));
                try {
                    c.addSeries(myTickSeries,true,false);
                } catch(Throwable t) {
                    t.printStackTrace(); // ... see below
                }
    
                return false;
            }
       });
    

    what I see thrown is the following... does this make any sense to you?

    Many thanks.

    • Bob Light

    com.google.gwt.core.client.JavaScriptException: (TypeError): m.redraw is not a function
    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.BaseChart.nativeAddSeries(BaseChart.java)
    at org.moxieapps.gwt.highcharts.client.BaseChart.addSeries(BaseChart.java:1492)
    at org.moxieapps.gwt.highcharts.client.BaseChart.addSeries(BaseChart.java:1471)
    at client.MyChart$2.onRedraw(MyChart.java:43)
    at org.moxieapps.gwt.highcharts.client.BaseChart.chartEventCallback(BaseChart.java:2370)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
    at java.lang.Thread.run(Thread.java:662)

     
  • Shawn Quinn

    Shawn Quinn - 2012-07-05

    Adding a series to a chart after is rendered is definitely supported and a core feature of both Highcharts and GWT Highcharts. Trying to add a series to a chart during the chart's redraw event feels a bit strange though and is nothing I've seen tried before, so that may not be supported by Highcharts itself. Does that code work if you run it elsewhere, instead of inside the redraw event handler? If so, you might have better luck if you use GWT's deferred scheduling instead. E.g.

        Scheduler.get().scheduleDeferred(new Command() {
            public void execute() {
                // ... create and add the series to the chart here
            }
        });
    

    Hope that helps, and keep us posted on what you find. If you continue to have trouble, if you can boil your scenario down to a simple working example and post it here we could try running it here to better see what's going on.

     

Log in to post a comment.