需要在HighChart中链接URL

时间:2013-10-16 09:10:07

标签: javascript php jquery highcharts

我正在使用HighChart插件绘制饼图/条形图。单击饼图部分时,我想链接其他页面,换句话说,我想重定向到其他页面。

演示链接:http://www.highcharts.com/demo/pie-basic

$(function () {
    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: 'Browser market shares at a specific website, 2010'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: [
                ['Firefox',   45.0],
                ['IE',       26.8],
                {
                    name: 'Chrome',
                    y: 12.8,
                    sliced: true,
                    selected: true
                },
                ['Safari',    8.5],
                ['Opera',     6.2],
                ['Others',   0.7]
            ]
        }]
    });
});

Fiddle Link: http://jsfiddle.net/aravindkumarit/M8a3X/

他们没有传递部件的ID,因此我无法为饼图部件编写任何事件。

1 个答案:

答案 0 :(得分:8)

添加

  events:{
      click: function (event) {
                 alert(event.point.name);
              // add your redirect code and u can get data using event.point
     }
 }
plotOptions.pie

中的

像这样

 plotOptions: {
        pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
                enabled: true,
                color: '#000000',
                connectorColor: '#000000',
                format: '<b>{point.name}</b>: {point.percentage:.1f} %'
            },
            events:{
              click: function (event) {
                  alert(event.point.name);
                  // add your redirect code and u can get data using event.point
              }
          }
        }
    }

DEMO