jquery - Highcharts : Donut Pie with URL

标签 jquery highcharts

我在 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/

相关文章:

javascript - 如何旋转 HighCharts 条形图使其垂直而不是水平?

highcharts - 向 Highcharts 图表添加日期范围过滤器

绘图区域外的 Highcharts 数据标签?

javascript - 向线 Highcharts 添加区域渐变

javascript - 如何从谷歌自定义搜索 API onclick 而不是 onload 加载图像

jQuery/HTML/CSS colspan 问题

javascript - 使用回调循环遍历数组

javascript - jQuery 不工作, "Zentabs"冲突?

vue.js - Highcharts 错误 #17 (Vue.js),columnrange 系列中

jquery - 来自 AJAX html 的主体类