21

我想在每一列的工具提示中显示多个系列数据

tooltip: {
    formatter: function() {
        return '<span style="color:#D31B22;font-weight:bold;">' +this.series.name +': '+ this.y +'<br/>'+
               '<b style="color:#D31B22;font-weight:bold;">'+this.x +'</b><span>';
    }
},

和数据

series: [{
    showInLegend: false,
    name: 'Total Click',
    data: [3000,200,50,4000],
    color: '#9D9D9D'
}, {
    showInLegend: false,
    name: 'Total View',
    data: [100,2000,3000,4000],
    color: '#D8D8D8'
}]

我是这样使用的,但在工具提示中一次只显示一个系列数据。我想显示这样的数据(Total View:100 and Total Click:3000)

4

3 回答 3

33

请尝试使用此代码

更新的演示

tooltip: {
        formatter: function() {
            var s = [];

            $.each(this.points, function(i, point) {
                s.push('<span style="color:#D31B22;font-weight:bold;">'+ point.series.name +' : '+
                    point.y +'<span>');
            });

            return s.join(' and ');
        },
        shared: true
    },
于 2013-10-11T09:46:15.950 回答
13

您需要使用共享参数http://api.highcharts.com/highcharts#tooltip.shared然后在格式化程序中迭代每个点。

于 2013-10-11T08:51:16.443 回答
2

如果有人在寻找散点图,这里是显示共享工具提示的解决方案。

formatter: function(args) {
    var this_point_index = this.series.data.indexOf( this.point );
    var this_series_index = this.series.index;
    var that_series_index = this.series.index == 0 ? 1 : 0; // assuming 2 series
    var that_series = args.chart.series[that_series_index];
    var that_point = that_series.data[this_point_index];
    return 'Client: ' + this.point.name +
           '<br/>Client Health: ' + this.x +
           '<br/>' + this.series.name + ' Bandwidth: ' + this.y + 'Kbps' +
           '<br/>' + that_series.name + ' Bandwidth: ' + that_point.y + 'Kbps';
}

Jsfiddle 链接到解决方案

于 2014-06-12T06:44:59.580 回答