Add handler to chart to fire when any pixel on chart is clicked

547 Views Asked by At

I am using GWT wrapper by MoxieGroup for Highcharts. How can I make it so that any click anywhere on the chart will fire an event. Thought this might be the right starting point

chart.addDomHandler(new ClickHandler() {

@Override
public void onClick(ClickEvent event) 
{
    Window.alert("Clicked");

}
}, ClickEvent.getType());
1

There are 1 best solutions below

0
On BEST ANSWER

It seems like highcharts has some trouble passing events through it, either by design or because of some conflict with the SVG. That said the MoxieGroup has a couple methods that should help you out.

This is the method you should use to add a click handler to the background of the chart. Clicking on the series, or near the series won't fire this handler.

chart.setClickEventHandler(new ChartClickEventHandler() {

    @Override
    public boolean onClick(ChartClickEvent chartClickEvent) {
        GWT.log("chart click"+chartClickEvent.getClientX());
        return false;
    }
});

The following handler will allow you to capture the click events when you click on a series.

chart.setSeriesPlotOptions(new SeriesPlotOptions()
    .setSeriesClickEventHandler(new SeriesClickEventHandler() {
        public boolean onClick(SeriesClickEvent clickEvent) {
            GWT.log("series click");
            return true;
        }
    })
);

Between the two of them you should be able to capture most of the click events on the chart.