Changing backgroundcolor of tooltip for a specific data point in Highcharts

自作多情 提交于 2021-01-01 07:40:20

问题


I have a Highcharts line chart and have tooltips enabled, however, I would like to change the background color of tooltip for just a single data point on the chart.
Is it possible to do so?
What I have so far
tooltip: { formatter: function () { return this.y; }, backgroundColor: '#68BD49', borderColor: '#000000', borderWidth: '1' },


回答1:


Yes it is possible, by using HTML option and define custom parameters. Obviously you can use CSS styles / classes disable padding/margins, but in the simplest way you can achive this in this way:

 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/



来源:https://stackoverflow.com/questions/14991075/changing-backgroundcolor-of-tooltip-for-a-specific-data-point-in-highcharts

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