我可以使用两种不同的格式化程序进行高图形工具提示吗? [英] Can I use two different formatters for highchart tooltips?

查看:100
本文介绍了我可以使用两种不同的格式化程序进行高图形工具提示吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张使用命名值的数据序列的高分表。在我的一个系列的工具提示中,我想引用该系列中的一个数据点。所以在这个答案的解决方案:如何在同一图形的每条曲线上的Highcharts上使用不同的格式?对我没有帮助。我需要的不仅仅是tooltipText,我需要一个格式化程序:



其中一个:

  formatter:function(){
return this.x +':'+ this.series.name +
'< br> $'+ Highcharts.numberFormat(this.y,0);
}

另一个:

  formatter:function(){
return'In'+ this.x +'the median value is'+ this.median +
'and the the总$'+ Highcharts.numberFormat(this.y,0);


解决方案 c>这个继承了聚焦的系列,你可以在格式化程序中添加一个 if / else ,并为每一个返回一个字符串,如下所示。

 工具提示:{
shared:false,
formatter:function(){
var text ='';
if(this.series.name =='MSFT'){
text = this.x +':'+ this.series.name +
'< br> $'+ Highcharts.numberFormat(this.y,0);
} else {
text ='In'+ this.x +'的中间值是'+ this.median +
'和总$'+ Highcharts.numberFormat(this.y ,0);
}
返回文本;
}
}

演示

I have a highcharts table with two data series that use named values. In my tooltips for one series, I want to reference a data point from the series. So the solution in this answer: How to use a different formatter on Highcharts in each curve of the same graphic? doesn't help me. I need more than just tooltipText, I need a formatter:

For one:

formatter: function() {
    return this.x + ': ' + this.series.name +
    '<br> $' + Highcharts.numberFormat(this.y, 0);
     }

And for the other:

formatter: function() {
    return 'In ' + this.x + ' the median value was' + this.median + 
    'and the total $' + Highcharts.numberFormat(this.y, 0);                        
 }

解决方案

Inside formatter this reffers to the focused serie, you can add an if/else inside the formatter and return a string for each one, like the following.

tooltip: {
    shared: false,
    formatter: function() {
        var text = '';
        if(this.series.name == 'MSFT') {
            text = this.x + ': ' + this.series.name +
                   '<br> $' + Highcharts.numberFormat(this.y, 0);
        } else {
            text = 'In ' + this.x + ' the median value was' + this.median +
                   'and the total $' + Highcharts.numberFormat(this.y, 0);
        }
        return text;
    }
}

demo

这篇关于我可以使用两种不同的格式化程序进行高图形工具提示吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆