* Highcharts *工具提示格式

时间:2015-11-26 12:23:32

标签: highcharts tooltip

我有这样的工具提示格式:

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

如何为series.name添加颜色,因为现在它们都是黑色的。在绘图后的图表中,不同的series.name有不同的颜色。

由于

1 个答案:

答案 0 :(得分:1)

使用它:

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

如果您的工具提示已共享,请使用以下代码

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

相关问题