How to Pass Custom Data to Highcharts Chart Click Event
Is it possible to pass custom data when rendering a Highcharts chart (a funnel in this case) so that when I bind a click event can I use that custom data point?
Currently all I can get is the "name" event.point.name
I provide for the label, but I also want to pass song_id
.
http://jsfiddle.net/y4a2end3/1/
Is there a place in the graphical code where I can add another data point like "song_id"?
series: [{
name: 'Song Plays',
data: [
['song_name1',123, 'song_id_1'], /* song_id_1 would be the custom data */
['song_name2',234, 'song_id_2']
]
}]
source to share
If you want to attach additional data to points in a series, you can initialize the points that need additional data as objects instead of arrays / int. For example, with code you could do:
series: [{
name: 'Song Plays',
data: [
{x:'song_name1', y:123, songid:'song_id_1'},
{x:'song_name2', y:234, songid:'song_id_2'}
]
}]
Then you can get it from the click point like event.point.songid
. See this JSFiddle demo with point click and tooltip.
Note that in many cases x
the facility is not required. It is often automatic and sequential.
source to share
You may try
alert(event.point.series.userOptions.data[event.point.x][2])
Updated script: http://jsfiddle.net/y4a2end3/2/
Or that:
alert(event.point.series.userOptions.data[event.point.series.data.indexOf(event.point)][2]);
source to share