javascript - Highcharts.js : get specific value from data to tooltip

标签 javascript highcharts data-visualization interactive donut-chart

我想根据this one制作一个Highcharts圆环图。只是我的数据看起来像这样:

data: [
                {y:40, color: colors[0], name: 'yoyo'},
                {y:0, color: colors[1],  name: 'dada'},
                {y:60, color: colors[2],  name: 'sasa'}
            ]

现在:当我将 mouseOver 函数更改为:

mouseOver: function(){
                        this.series.chart.innerText.attr({text: this.name});
                    },

然后我就可以从我的数据中检索name键的值。但是,当我想将其添加到工具提示中时,以下代码不起作用(代码添加在原始代码中的 tooltip: 之后):

{
      formatter: function() {
                             return '<b>'+this.name+'</b>';
                    }
                },

当我将 this.name 更改为 this.y 时,我再次获得正确的值。谁能告诉我如何检索工具提示的 this.name 吗?任何帮助将非常感激。

最佳答案

通过以下方式更改格式化程序:

formatter: function() {
    return '<b>' + this.key + '</b>';
}

当你不知道你的对象怎么样时,在代码中使用 console.log(myObject) 并检查你的 js 控制台。

关于javascript - Highcharts.js : get specific value from data to tooltip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41022531/

相关文章:

javascript - Twitter Bootstrap 日期选择器 : how to enable only specific daterange

javascript - 两个 css 代码相互重叠,看不到其中一个

python - 从预训练模型中可视化样本的优缺点

javascript - 在 IE 中将 c# 文本框作为 javascript 参数传递(Chrome 有效)

javascript - React Native 中的透明覆盖

javascript - 更改 Django 中多条形图的颜色

jquery - 如何格式化 Highcharts ?

javascript - Highcharts 工具提示系列名称前面的奇怪字符

r - 如何在r中的highcharter中为树形图添加数据标签?

c# - 数据图表展示