Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts: Area clickable

Tags:

highcharts

I have an area Highchart chart. Added a click event to the chart, like this:

plotOptions: {
                area: {
                    marker: {
                        enabled: false
                    },
                    cursor: 'Pointer',
                    stacking: 'normal',
                    events: {
                        click: function(event) {
                          alert("hi there");
                        }
                    }                   
                }
            }

It works fine. The problem is that you can only click very near to a line, but not on the area below the line, it is not clickable.

Is there a setting that I overlooked?

like image 654
eddy147 Avatar asked Nov 11 '11 09:11

eddy147


3 Answers

You can use this trackByArea: true area function in plotOptions

trackByArea: Boolean

Since 1.1.6 Whether the whole area or just the line should respond to mouseover tooltips and other mouse or touch events. Defaults to false.

Combine this with the click event

click: Function

Fires when the series is clicked. The this keyword refers to the series object itself. One parameter, event, is passed to the function. This contains common event information based on jQuery or MooTools depending on which library is used as the base for Highcharts. Additionally, event.point holds a pointer to the nearest point on the graph.

ex:

plotOptions: { area: { **trackByArea: true**, marker: { enabled: false },..
like image 122
shaheer ar Avatar answered Oct 21 '22 17:10

shaheer ar


Actually, you can do exactly what you want out of the box. The chosen answer was only looking at events for the PlotOptions object; you need to look at events for the Chart object.

Documentation and example at: http://www.highcharts.com/ref/#chart-events--click

When you click on the background, it fires the event.

chart: {
        renderTo: 'container',
        events: {
            click: function(event) {
                alert ('x: '+ event.xAxis[0].value +', y: '+
                      event.yAxis[0].value);
            }
        }        
    },
like image 9
JD Smith Avatar answered Oct 21 '22 18:10

JD Smith


According to the highcharts documentation, the click event only covers clicking on the series itself, so it will not register click events for clicking beneath the line.

To do what you want, you may need to handle things on your own by using the mouseOver event. Unforutnately, this event fires when the mouse hovers over the graph, which would mean you'd need to figure out where the mouse is on the graph and so forth.

Alternatively, you could modify the highcharts source code to suit your needs, or extend it, but in any case, I do not believe that this can be done easily.

like image 3
NT3RP Avatar answered Oct 21 '22 18:10

NT3RP