我在 Highcharts 中有一个饼图。单击饼图的一部分应加载与该数据系列关联的 URL。例如,如果有一个 25% 的切片,其 url 为 yahoo.com
,还有一个 35% 的切片为 google.com
,则单击 35% 切片应采取用户访问 google.com
。
这是我在该系列中添加的内容:
// ...
point: {
events: {
click: function(e) {
location.href = e.point.url;
e.preventDefault();
}
}
}
// ...
data = [{
y: 55.11,
color: colors[0],
url: 'www.google.com',
drilldown: {
name: 'MSIE versions',
categories: ['MSIE 6.0', 'MSIE 7.0', 'MSIE 8.0', 'MSIE 9.0'],
data: [10.85, 7.35, 33.06, 2.81],
url: 'www.google.com',
color: colors[0]
}
}, { .......many more dataset ...
我有一个如上所述的 JS fiddle 示例,但它 is not working .
在同一示例中,有人建议在系列中添加 url
,但这会使所有切片都指向相同的 URL。
这个例子类似but also does not work .
最佳答案
调试损坏的示例后,问题是 url
未包含在传递到图表的数据中:
// add browser data
browserData.push({
name: categories[i],
y: data[i].y,
color: data[i].color,
// missing this line!
url: data[i].url
});
完成后,就像 docs describe 一样简单:
point: {
events: {
click: function(e) {
location.href = this.options.url;
}
}
}
关于jquery - Highcharts : Donut Pie with URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17886592/