Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts: show stack total in shared tooltip, via footerFormat property

I have a stacked bar chart, with a shared tooltip, and I am trying to pull the stack total into the tooltip via the footerFormat property.

I thought this would be a simple property I could access, but I have not found an option for it that works.

Am I missing something obvious, or do I have to do this in a more complicated manner?

(if I've missed a duplicate of this question, please let me know, I was not able to find the specific circumstance I am looking to accomplish discussed)

code:

tooltip : {
    shared          : true,
    useHTML         : true,
    headerFormat    : 
         '<table class="tip"><caption>Group {point.key}</caption>'
        +'<tbody>', 
    pointFormat     : 
         '<tr><th style="color: {series.color}">{series.name}: </th>'
        +'<td style="text-align: right">${point.y}</td></tr>',
    footerFormat    : 
         '<tr><th>Total: </th>'
        +'<td style="text-align:right"><b>${???}</b></td></tr>'
        +'</tbody></table>'
}
  • Fiddle: http://jsfiddle.net/jlbriggs/AeLFZ/
like image 963
jlbriggs Avatar asked Jun 24 '14 15:06

jlbriggs


2 Answers

footerFormat does not have acces to ${point}. See footerFormat documentation.

If you want to have a table with each point using shared:true you need to use the formatter function like this:

formatter: function() {
            var tooltip='<table class="tip"><caption>Group '+this.x+'</caption><tbody>';
            //loop each point in this.points
            $.each(this.points,function(i,point){
                tooltip+='<tr><th style="color: '+point.series.color+'">'+point.series.name+': </th>'
                      + '<td style="text-align: right">'+point.y+'</td></tr>'
            });
            tooltip+='<tr><th>Total: </th>'
            +'<td style="text-align:right"><b>'+this.points[0].total+'</b></td></tr>'
            +'</tbody></table>';
            return tooltip;
        }    

http://jsfiddle.net/AeLFZ/10/

like image 87
Abraham Uribe Avatar answered Nov 02 '22 12:11

Abraham Uribe


Here is my approach using footerFormat and its 100% working

tooltip: {
     shared: true,
     headerFormat: '<b>Week {point.x}</b><br>',
     pointFormat: '<b>{series.name}:</b> {point.y} ( {point.percentage:.0f}% )<br>',
     footerFormat: '<b>Total:  {point.total} </b>'
},

enter image description here

like image 7
SoliQuiD Avatar answered Nov 02 '22 11:11

SoliQuiD