2017-05-13 57 views
-1

如何将工具提示颜色设置为与高跷图5中的条形颜色相同?根据条形颜色更改高耸的工具提示颜色

我用下面的代码,但只提示的边框颜色似乎正在改变

tooltip: { 
        backgroundColor: null, 
        borderWidth: 1, 
        borderColor: null, 
        formatter: function(){ 

         return '<div style="background-color:'+ this.series.color +'!important; font-weight:bold;color:#fff" class="tooltip"> ' + this.y + '</div>'; 
        }, 

        }, 

注意的是,上面的代码工作在Highcharts 4,但不是在版本5

回答

1

你缺少useHTML: true,在提示选项

tooltip: { 
     valueSuffix: ' millions', 
     useHTML: true, 
     backgroundColor: null, 
     borderWidth: 1, 
     borderColor: null, 
     formatter: function(){ 
      return '<div style="background-color:'+ this.series.color +'!important; font-weight:bold;color:#fff" class="tooltip"> ' + this.y + '</div>'; 
     } 
    }, 

Fiddle演示

更新

使用Tooltip.prototype.refresh加入这现有代码

const H = Highcharts; 

    H.wrap(H.Tooltip.prototype, 'refresh', function (p, point, mouseEvents) { 
    p.call(this, point, mouseEvents); 

     const label = this.label; 

     if (point && label) { 
      label.attr({ 
      fill: point.series.color 
      }); 
     } 
     }); 

Updated Fiddle

+0

即使我使用'useHTML:成立,'它不工作...如果你检查小提琴只有文字背景改变不是整个工具提示 – LiveEn

+0

任何示例图像显示你想要的 –

+0

检查更新的代码 –