在Highcharts中进行深入分析时更改标题

Kri*_*fer 10 javascript highcharts

我正在寻找一种在使用下钻时在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]
            ]
        }]
    }
})
});
Run Code Online (Sandbox Code Playgroud)

Hal*_*and 21

例如,使用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
});
Run Code Online (Sandbox Code Playgroud)

看到这个JSFiddle演示.

  • 在事件处理程序中,"this"指的是图表对象.所以你可以调用`this.setTitle(...)`. (2认同)