最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to pass custom data into Highcharts graph click event - Stack Overflow

programmeradmin3浏览0评论

Is possible to pass custom data when rendering a Highcharts graph (funnel, in this case), so that when I bind a click event, I can use this custom data point?

Currently, all that I can get is the "name" event.point.name, which I provide for the Label, but I also want to pass a song_id too.

/

Is there a place in the graph code that 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']
        ]
    }]

Is possible to pass custom data when rendering a Highcharts graph (funnel, in this case), so that when I bind a click event, I can use this custom data point?

Currently, all that I can get is the "name" event.point.name, which I provide for the Label, but I also want to pass a song_id too.

http://jsfiddle/y4a2end3/1/

Is there a place in the graph code that 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']
        ]
    }]
Share Improve this question edited Aug 11, 2014 at 3:48 d-_-b asked Aug 11, 2014 at 3:18 d-_-bd-_-b 23.3k43 gold badges171 silver badges287 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

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/ints. For example, with your 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'}
    ]
}]

You can then get it from the point on click as event.point.songid. See this JSFiddle demo using point click and tooltip.

Note that in many cases x in the object will not be required. It is often automatic and sequential.

You can try

alert(event.point.series.userOptions.data[event.point.x][2])

Updated fiddle: http://jsfiddle/y4a2end3/2/

Or this:

alert(event.point.series.userOptions.data[event.point.series.data.indexOf(event.point)][2]);
发布评论

评论列表(0)

  1. 暂无评论