HighCharts : Adding Hyperlinks to the X-Axis of the chart

后端 未结 2 947
野趣味
野趣味 2021-02-20 17:24

I have been using HighCharts in my PHP website by migrating it from older charts and I am very impressed by the number of graph options and functions with this library.

相关标签:
2条回答
  • 2021-02-20 18:13

    It's been a while since I've done work in highcharts, but I believe you just need to provide a formatter function. For example:

    xAxis: {
        categories: [
            'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
        ],
        labels: {
            formatter: function () {
                return '<a>' + this.value + '</a>'
            },
            useHTML: true
        }
    },
    
    0 讨论(0)
  • 2021-02-20 18:19
    var categoryLinks = {
            'Foo': 'http://www.google.com',
            'Bar': 'http://www.facebook.com',
            'Foobar': 'http://www.stackoverflow.com'
        };
        $('#container').highcharts({
            xAxis: {
                categories: ['Foo', 'Bar', 'Foobar'],
    
                labels: {
                    formatter: function () {
                        return '<a href="' + categoryLinks[this.value] + '">' +
                            this.value + '</a>';
                    }
                }
            },
            series: [{
                data: [300, 200, 600]
            }]
        });
    
    0 讨论(0)
提交回复
热议问题