Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return xAxis category on click

Tags:

highcharts

I can't seem to get the category from a Highchart returned on a click event on the chart itself. In other words, this works fine:

plotOptions: { 
  series: { 
    events: { 
      click: function(ev) {
        console.log(ev.point.category); // outputs category
      }
    }
  }
}

However, what I'd like is to be able to get the category when a user clicks anywhere on the chart, not just on the point. It would look something like this

chart: { 
  events: {
    click: function(ev) {
      console.log(ev.xAxis[0].category); // undefined because doesn't exist - sure would be nice, tho
    }
  }
}

I've combed through both the event and the highcharts objects here, but without being able to find how to identify which category is associated with the x-value being returned.

like image 812
dinocarl Avatar asked Feb 04 '26 00:02

dinocarl


1 Answers

You can get position x value and map to categories. Example:

click:function(e){
                alert('x: ' + categories[Math.floor(e.xAxis[0].value)]);
}

http://jsfiddle.net/pev5zos8/

like image 121
Sebastian Bochan Avatar answered Feb 13 '26 07:02

Sebastian Bochan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!