highchart total in tooltip

断了今生、忘了曾经 提交于 2019-12-22 06:29:30

问题


i am using this code to display a shared tooltip:

tooltip: {
    crosshairs: true,
    shared: true,
    headerFormat: 'KW {point.key}<table>',
    pointFormat: '<tr><td style=\"color: {series.color}\">{series.name}: <b></td><td>{point.y} USD</b></td></tr>',
    useHTML: true,
    footerFormat: '</table>',
    valueDecimals: 2
},

Now i like to add all point.y values as a total value of the point. But how can i loop the point.y of each series to calculate the total value?


回答1:


Excatly, see example: http://jsfiddle.net/65bpvudh/7/

tooltip: {
    formatter: function() {
        var s = '<b>'+ this.x +'</b>',
            sum = 0;

        $.each(this.points, function(i, point) {
            s += '<br/>'+ point.series.name +': '+
                point.y +'m';
            sum += point.y;
        });

        s += '<br/>Sum: '+sum

        return s;
    },
    shared: true
},



回答2:


More easy, use total property of point:

tooltip: {
    formatter: function() {
        var s = '<b>'+ this.x +'</b>';
        $.each(this.points, function(i, point) {
            s += '<br/>'+ point.series.name +': '+ point.y;
        });
        s += '<br/>Total: '+ this.points[0].total
        return s;
    },
    shared: true
},

Check this reference




回答3:


Use the footerFormat property (since version 2.2) with {point.total} to easily show the total without having to re-define the complete formatter function:

tooltip: {
    footerFormat: 'Sum: <b>{point.total}</b>',
    shared: true,
},


来源:https://stackoverflow.com/questions/14717353/highchart-total-in-tooltip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!