在Highcharts中向下钻取时更改标题

Change title when drilldown in Highcharts

本文关键字:标题 钻取 Highcharts      更新时间:2023-09-26

我正在寻找一种在Highcharts中显示信息文本的方法。我想要一个文本,告诉我的访问者,另一个图表已经显示。例如标题:"新图表-更多关于动物"

http://jsfiddle.net/6zYmJ/

你知道怎么做吗?

$(function () {    
// Create the chart
$('#container').highcharts({
    chart: {
        type: 'column'
    },
    title: {
        text: 'Basic drilldown'
    },
    xAxis: {
        type: 'category'
    },
    legend: {
        enabled: false
    },
    plotOptions: {
        series: {
            borderWidth: 0,
            dataLabels: {
                enabled: true,
            }
        }
    },
    series: [{
        name: 'Things',
        colorByPoint: true,
        data: [{
            name: 'Animals',
            y: 5,
            drilldown: 'animals'
        }, {
            name: 'Fruits',
            y: 2,
            drilldown: 'fruits'
        }, {
            name: 'Cars',
            y: 4,
            drilldown: 'cars'
        }]
    }, {
        name: 'Things',
        colorByPoint: true,
        data: [{
            name: 'Animals2',
            y: 5,
            drilldown: 'animals2'
        }, {
            name: 'Fruits2',
            y: 2,
            drilldown: 'fruits2'
        }, {
            name: 'Cars2',
            y: 4,
            drilldown: 'cars2'
        }]
    }],
    drilldown: {
        series: [{
            id: 'animals',
            data: [
                ['Cats', 4],
                ['Dogs', 2],
                ['Cows', 1],
                ['Sheep', 2],
                ['Pigs', 1]
            ]
        }, {
            id: 'fruits',
            data: [
                ['Apples', 4],
                ['Oranges', 2]
            ]
        }, {
            id: 'cars',
            data: [
                ['Toyota', 4],
                ['Opel', 2],
                ['Volkswagen', 2]
            ]
        },{
            id: 'animals2',
            data: [
                ['Cats', 4],
                ['Dogs', 2],
                ['Cows', 1],
                ['Sheep', 2],
                ['Pigs', 1]
            ]
        }, {
            id: 'fruits2',
            data: [
                ['Apples', 4],
                ['Oranges', 2]
            ]
        }, {
            id: 'cars2',
            data: [
                ['Toyota', 4],
                ['Opel', 2],
                ['Volkswagen', 2]
            ]
        }]
    }
})
});

例如使用drilldowndrillup事件(API),一对变量和Chart.setTitle (API)。这样的:

var defaultTitle = "Basic drilldown";
var drilldownTitle = "More about ";
var chart = new Highcharts.Chart({
    chart: {
        type: 'column',
        renderTo: 'container',
        events: {
            drilldown: function(e) {
                chart.setTitle({ text: drilldownTitle + e.point.name });
            },
            drillup: function(e) {
                chart.setTitle({ text: defaultTitle });
            }
        }
    },
    title: {
        text: defaultTitle
    },
    // ... more options
});