Search code examples
highchartstooltip

*Highcharts* Tooltip format


I have a tooltip format like this:

tooltip:  {
formatter: function() {
     return   Highcharts.dateFormat('%A, %b %e, %Y',new Date(this.x)) +'<br/>'+ this.series.name + ': ' + '<b>'+ this.y +'</b>';
 }
};

How can I add color to my series.name because now they all black. In my chart after drawing, different series.name has different colors.

Thanks


Solution

  • use this:

    tooltip: {
    formatter: function() {
        var toolTipTxt = '<b>'+ this.x +'</b>';        
            toolTipTxt += '<br/><span style="color:'+ this.point.series.color +'"> ' + this.point.series.name + ': ' + this.y+' </span>';
    
        return toolTipTxt;
    } 
    
    }
    

    See the working fiddle here

    If your tooltip is shared then use following code

    tooltip: {
    formatter: function() {
        var toolTipTxt = '<b>'+ this.x +'</b>';  
          $.each(this.points, function(i, point) {
            toolTipTxt += '<br/><span style="color:'+ point.series.color +'">  ' + point.series.name + ': ' + point.y+'</span>';
        });
    
    
        return toolTipTxt;
    } ,shared:true
     }
    

    See the demo of different color in tooltip for shared tooltip here