*Highcharts* Tooltip format

只愿长相守 提交于 2019-12-12 04:16:56

问题


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



来源:https://stackoverflow.com/questions/33938646/highcharts-tooltip-format

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