*Highcharts* Tooltip format

2019-08-18 06:10发布

问题:

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

回答1:

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