Menu

Multiple listeners on a chart do not behave correctly

Preston
2011-09-01
2012-08-30
  • Kombucha

    Kombucha - 2011-09-13

    Hi,

    I'm sure the fix is already in the pipe, but for those of you who are impatient, here's what you'll have to do :

    Original code (in the function nativeRenderChart) :

    // Add in GWT interceptor callback functions for the various series point event handlers
    for (var type3 in pointEventHandlerFlags) {
        if (type3.indexOf("gwt") < 0 && pointEventHandlerFlags[type3]) {
            options.plotOptions = options.plotOptions || {};
            options.plotOptions.series = options.plotOptions.series || {};
            options.plotOptions.series.point = options.plotOptions.series.point || {};
            options.plotOptions.series.point.events = options.plotOptions.series.point.events || {};
    
            var pointEventType = type3;
            options.plotOptions.series.point.events[type3] = function(e) {
                return self.@org.moxieapps.gwt.highcharts.client.BaseChart::pointEventCallback(Lcom/google/gwt/core/client/JavaScriptObject;Lcom/google/gwt/core/client/JavaScriptObject;Ljava/lang/String;)(this, e, pointEventType);
            }
        }
    }
    

    What's wrong with this code is the way the pointEventType is passed to the function. Basically, by the moment the callbacks are called, the pointEventType will be the same for all of them (that is, the last value of the loop). I'm an absolute noob by no means an expert in javascript, so if you wanna understand why this happens, please follow this link.
    So here's how it would be fixed in our case :

    // Add in GWT interceptor callback functions for the various series point event handlers
    for (var type3 in pointEventHandlerFlags) {
        if (type3.indexOf("gwt") < 0 && pointEventHandlerFlags[type3]) {
            options.plotOptions = options.plotOptions || {};
            options.plotOptions.series = options.plotOptions.series || {};
            options.plotOptions.series.point = options.plotOptions.series.point || {};
            options.plotOptions.series.point.events = options.plotOptions.series.point.events || {};
    
            options.plotOptions.series.point.events[type3] = (function(type) {
                return function(event) {
                    return self.@org.moxieapps.gwt.highcharts.client.BaseChart::pointEventCallback(Lcom/google/gwt/core/client/JavaScriptObject;Lcom/google/gwt/core/client/JavaScriptObject;Ljava/lang/String;)(this, event, type);
                }
            })(type3);
        }
    }
    

    You'll have to make this kind of change at several places in the nativeRenderChart method.

    
    
     

    Last edit: Kombucha 2011-09-21
    • Robert Light

      Robert Light - 2012-08-30

      I'm trying to figure out how to add my own PointClickEventHandler onto a series of "flags" which are displayed "onAxis". It appears that this code you provided has been included in V1.4.0 (though I am not sure).

      Right now I have the following code and it does NOT work... I haven't made any changes to BaseChart or anything in nativeRenderChart...

          Series flagSeries = createSeries().setName("Events");
          flagSeries.setPlotOptions( 
              new SeriesPlotOptions().setPointClickEventHandler( new PointClickEventHandler() {
      
                @Override
                public boolean onClick(PointClickEvent pointClickEvent) {
                  Window.alert("We got a click - yeah ");
                  return true;
                }
      
              }) 
          );
      

      Any idea on what I'm doing wrong??

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.