简体   繁体   English

如何在饼图工具提示中显示特定类别的自定义文本

[英]How to display custom text for a specific category in pie chart tool tip

I have a pie chart and I want to display custom text specifically for a specific category when the user hovers over the category. 我有一个饼图,当用户将鼠标悬停在类别上时,我想显示专门针对特定类别的自定义文本。

JS Fiddle Link: https://jsfiddle.net/mewohraz/1/ JS小提琴链接: https : //jsfiddle.net/mewohraz/1/

tooltip: {
    pointFormat: '{point.custom} (point.category == 'Internet Explorer) ? 'display customtext'
},

eg when the user hovers over Internet Explorer, I want to display a bullet list of versions. 例如,当用户将鼠标悬停在Internet Explorer上时,我想显示项目符号列表。 The text will be hard coded so it's not coming from data series. 文本将进行硬编码,因此它不是来自数据系列。

How do I do this? 我该怎么做呢?

You can user the formatter function of the tooltip option to defined your own text : tooltip.formatter 您可以使用tooltip选项的formatter功能来定义自己的文本: tooltip.formatter

tooltip: {
    formatter: function(){
        if(this.point.name == "Internet Explorer")
            return "my custom text" ;
        else
            return '<span style="color: ' + this.point.color + '">' + this.point.name + '</span><br/>' + this.point.custom ;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM