Menu

Reset Zoom button not working in GWT Moxie Chart

2012-11-15
2014-08-14
  • Vairavan Murugappan

    Hi All,
    I am new to Moxie charts and this is probably my first try of this.
    I took the example scatter chart code from the showcase application and added a series selection handler. when i have a series selection handler

    package com.example.moxieChart.client;
    
    import com.google.gwt.core.client.EntryPoint;  
    import com.google.gwt.user.client.Window;
    import com.google.gwt.user.client.ui.RootPanel;  
    import org.moxieapps.gwt.highcharts.client.*;  
    import org.moxieapps.gwt.highcharts.client.events.ChartSelectionEvent;
    import org.moxieapps.gwt.highcharts.client.events.ChartSelectionEventHandler;
    
    public class MoxieChart implements EntryPoint {
    
    public void onModuleLoad() {  
        RootPanel.get().add(createChart());  
    }
    
    public Chart createChart() {
    
        final Chart chart = new Chart()  
            .setType(Series.Type.SCATTER)
            .setZoomType(Chart.ZoomType.X_AND_Y);
    
        chart.setSelectionEventHandler(new ChartSelectionEventHandler() {
    
            @Override
            public boolean onSelection(ChartSelectionEvent e) {
                rangeChange(e.getXAxisMin(),e.getXAxisMax());
                return true;
            }
    
        });
    
        chart.addSeries(chart.createSeries()    
            .setPoints(new Number[][] {  
                {161.2, 51.6}, {167.5, 59.0}, {159.5, 49.2}, {157.0, 63.0}, {155.8, 53.6},
    
            })  
        );
    
        return chart;  
        }
    
    private void rangeChange(double min, double max){
        String message = "Min ="+ min+ " Max ="+ max;
        Window.alert(message);
    }
    }
    

    So this one gives me alert message when ever i zoom in, but after that the reset zoom button doesn't work. But if remove the rangeChange function call in the onSelection event it works. What am i doing wrong here?

     
  • Shawn Quinn

    Shawn Quinn - 2012-12-04

    Interesting, I was able to reproduce this issue as well. It appears that when you click the "reset zoom" button the SelectionEventHandler is getting called again, which would be fine, except for the fact that the native event is missing the "xAxis" and "yAxis" properties. So, when you call "e.getXAxisMin()" method the browser is running into an "Object undefined" error. To work around the issue, you can use the following JSNI trick:

    public Chart createChart() {
        final Chart chart = new Chart()
            .setType(Series.Type.SCATTER)
            .setZoomType(Chart.ZoomType.X_AND_Y);
    
        chart.setSelectionEventHandler(new ChartSelectionEventHandler() {
            public boolean onSelection(ChartSelectionEvent e) {
                if(hasProperty(e.getNativeEvent(), "xAxis")) {
                    rangeChange(e.getXAxisMin(), e.getXAxisMax());
                }
                return true;
            }
        });
    
        chart.addSeries(chart.createSeries()
            .setPoints(new Number[][]{
                {161.2, 51.6}, {167.5, 59.0}, {159.5, 49.2}, {157.0, 63.0}, {155.8, 53.6},
            })
        );
    
        return chart;
    }
    
    private static native boolean hasProperty(JavaScriptObject obj, String key) /*-{
        return (typeof obj[key] != "undefined");
    }-*/;
    

    Let us know if approach will work for what you're trying to accomplish.

     
    • Michael Margozzi

      I have the same issue. i tried your work around but it didn't solve the problem. I sort of suspected it wouldn't. My listener is NOT getting called twice. The error must be in the library itself. It is unfortunate that the previous person never got back to you. Any other suggestions for how to resolve this? Surely others must be pro programmatically trying to zoom in on the charts.

       

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.