How to get multiple series data in tooltip highcha

2019-02-05 20:32发布

I want to display multiple series Data in tooltip on every column

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>';
    }
},

and Data

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'
}]

I am using like this but in tool tip only one series data is showing at a time. I want to display Data like this (Total View:100 and Total Click:3000 )

3条回答
小情绪 Triste *
2楼-- · 2019-02-05 21:15

please try using this code

updated DEMO

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
    },
查看更多
3楼-- · 2019-02-05 21:17

You need to use shared parameter http://api.highcharts.com/highcharts#tooltip.shared and then in formater iterate on each point.

查看更多
来,给爷笑一个
4楼-- · 2019-02-05 21:29

If anybody looking for scatterplot, here is solution to show shared tooltip.

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 link to Solution

查看更多
登录 后发表回答