javascript Highcharts - 为系列数据提供 URL 以打开可点击链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16176390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Highcharts - Provide URL's for series data to open clickable link
提问by agrublev
I would like to add a url to each of my data points inside my series that when clicked user is redirected to that page. For example jsfiddle.
我想为我的系列中的每个数据点添加一个 url,单击时用户将被重定向到该页面。例如jsfiddle。
series:[{data: [ [123.12,'http://xyz.com'],[332.32,'http://zzs.com'] ] }]
I was able to get the points to be clickable, but how I actually get them to find the point I am clicking on and which url to use I can't figure out. I can obviously hack it by using an alternative array that stores the links... but I would like to use chart as it's meant.
我能够获得可点击的点,但是我实际上如何让它们找到我点击的点以及我无法弄清楚要使用的网址。我显然可以通过使用存储链接的替代数组来破解它……但我想按原意使用图表。
Now that it has been solved for future reference to be able to add links to your points here is the code:
现在已经解决了供将来参考,可以在此处添加指向您的点的链接,代码如下:
回答by Mark
Here's one way to do this (fiddle here):
这是执行此操作的一种方法(此处小提琴):
series: [{
name: 'Batch',
URLs: ['www.google.com', null, null, 'www.yahoo.com', null, null, 'www.cnn.com', null, null, 'www.minecraft.net'], // pass in array of URLs
data: [4375.48, 113599.39, 1278, 83950.12, 6579.65, 94582, 1285.65, 48700.39, 500, 62917.27],
color:'#b8ecce',
point: {
events: {
click: function() {
var someURL = this.series.userOptions.URLs[this.x]; // onclick get the x index and use it to find the URL
if (someURL)
window.open('http://'+someURL);
}
}
}
}],
回答by Sebastian Bochan
You can use structure:
您可以使用结构:
data:[{
y:10,
ownURL:'http://www.google.com'
},{
y:11,
ownURL:'http://www.google2.com'
},{
y:5,
ownURL:'http://www.google3.com'
}]
and then you have ability to "get" this value by
然后你有能力“得到”这个值
this.point.options.ownURL