【问题标题】:How to hyperlink bar graph in highcharts如何在highcharts中超链接条形图
【发布时间】:2012-09-25 04:20:27
【问题描述】:

我有一个根据我的数据库中的数据呈现数据的 highcharts。我正在使用“bar”类型。现在我希望当用户单击该栏时,它会重定向到特定页面或例如另一个网站。我用谷歌搜索但无法得到答案。这是我正在使用的代码。

$(function () {
var chart;
$(document).ready(function() {
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'bar'
        },
        title: {
            text: 'Historic World Population by Region'
        },
        subtitle: {
            text: 'Source: Wikipedia.org'
        },
        xAxis: {
            categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'],
            title: {
                text: null
            }
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Population (millions)',
                align: 'high'
            },
            labels: {
                overflow: 'justify'
            }
        },
        tooltip: {
            formatter: function() {
                return ''+
                    this.series.name +': '+ this.y +' millions';
            }
        },
        plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true
                }
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -100,
            y: 100,
            floating: true,
            borderWidth: 1,
            backgroundColor: '#FFFFFF',
            shadow: true
        },
        credits: {
            enabled: false
        },
        series: [{
            type: 'bar',
                    point: {
                      events: {
                        click: function(e) {

                           this.slice();
var clicked = this;
setTimeout(function(){
location.href = clicked.config[2];
                           }, 500)
                           e.preventDefault();
                        }
                     }
                   },
data: [['Com',107,'http://www.google.com']]
        }]
    });
});

});

【问题讨论】:

    标签: jquery highcharts


    【解决方案1】:

    这是有关如何执行此操作的文档的网址:http://api.highcharts.com/highcharts#plotOptions.series.point.events.click

    这是一个很好的示例:http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/plotoptions/series-point-events-click-url/

    您要更新的代码部分在这里:

    plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true
                }
            },
            series: {
                point: {
                    events: {
                        click: function(){
                           // do whatever here
                        }
                    }
                }
            }
    
        }
    

    【讨论】:

      【解决方案2】:

      Uncaught TypeError: Object #<Object> has no method 'slice'

      这是下面一行产生的错误。

      this.slice();

      删除它。

      demo

      上面的演示只会触发你绑定事件的系列的点击,如果你想将它绑定到所有系列使用@Jamiec建议。

      【讨论】:

        猜你喜欢
        • 2018-06-28
        • 2015-11-27
        • 2013-05-10
        • 1970-01-01
        • 2014-04-04
        • 1970-01-01
        • 1970-01-01
        • 2018-05-06
        • 1970-01-01
        相关资源
        最近更新 更多