【问题标题】:Changing backgroundcolor of tooltip for a specific data point in Highcharts更改 Highcharts 中特定数据点的工具提示的背景颜色
【发布时间】:2013-02-20 22:22:41
【问题描述】:

我有一个 Highcharts 折线图并启用了工具提示,但是,我想为图表上的单个数据点更改工具提示的背景颜色。
有可能吗?
到目前为止我有什么
tooltip: { formatter: function () { return this.y; }, backgroundColor: '#68BD49', borderColor: '#000000', borderWidth: '1' },

【问题讨论】:

    标签: highcharts


    【解决方案1】:

    是的,可以通过使用 HTML 选项并定义自定义参数。显然,您可以使用 CSS 样式/类禁用填充/边距,但以最简单的方式,您可以通过这种方式实现:

     tooltip: {
            useHTML:true,
            formatter: function() {
                console.log(this);
                if(this.point.customBck)
                    return '<div style="background-color:red;">The value for <b>'+ this.x + '</b> is <b>'+ this.y +'</b></div>';
                else
                    return '<div>The value for <b>'+ this.x + '</b> is <b>'+ this.y +'</b></div>';
            }
        },
    

    http://jsfiddle.net/XnLpH/1/

    【讨论】:

    • 太棒了!谢谢塞巴斯蒂安。
    • 有没有办法动态设置整个工具提示的背景颜色?这只会设置工具提示文本的背景..
    • 应该在什么条件下应用?每个点应该有自己的背景或每个系列?
    猜你喜欢
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 2015-06-28
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多