Highstock / Highcharts上每条线的不同后缀 [英] A different suffix for each line on Highstock/Highcharts

查看:102
本文介绍了Highstock / Highcharts上每条线的不同后缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有简单的方法在每行上使用不同的后缀值?



现在我有3行,我试图为每个后缀更改后缀,但我只能使用格式化函数找到它。



但是,如果我使用格式化函数,我需要编辑每个工具提示,使它像默认的一样,我不知道默认格式。



我的意思是,像改变颜色这样简单的方法,我们可以简单地做:

  {
name:'First line',
type:'line',
color:'#33CC66',
zIndex:0,
data:[...]
}


解决方案

我认为这是你想要的。您可以在每个系列中指定工具提示属性并使用valueSuffix:

http:// jsfiddle .net / aXvcw /

 工具提示:{
格式化程序:function(){
返回this.y +''+ this.series.tooltipOptions.valueSuffix;
}
},
系列:[{
name:'Rainfall',
type:'column',
yAxis:1,
数据:[49.9,71.5,106.4,129.2,144.0,176.0,135.6,148.5,216.4,194.1,95.6,54.4],
工具提示:{
valueSuffix:'mm'
}

},{
名称:'温度',
类型:'样条线',
数据:[7.0,6.9,9.5,14.5,18.2,21.5, 25.2,26.5,23.3,18.3,13.9,9.6],
工具提示:{
valueSuffix:'°C'
}
}]

从本演示中修改: http ://www.highcharts.com/demo/combo-dual-axes



您不需要提供工具提示格式化程序功能,但如果你想要的不是默认值,那你可以如何访问系列值eSuffix。

Is there a easy way to use different suffix values on each line?

Right now I have 3 lines, I'm trying to change the suffix for each, but I was only able to find it using the formatter function.

But if I use the formatter function I need to edit every tooltip, make it just like the default one, and I don't know the default format.

I mean, a easy way like changing colors, what we can simply do:

{
name: 'First line',
type: 'line',
color: '#33CC66',
zIndex: 0,
data: [ ... ]
}

解决方案

I think this is what you want. You can specify the tooltip attribute on each series and use valueSuffix :

http://jsfiddle.net/aXvcw/

        tooltip: {
            formatter : function() {
                 return this.y + ' ' +  this.series.tooltipOptions.valueSuffix;
            }
        },
        series: [{
            name: 'Rainfall',
            type: 'column',
            yAxis: 1,
            data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
            tooltip: {
                valueSuffix: ' mm'
            }

        }, {
            name: 'Temperature',
            type: 'spline',
            data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6],
            tooltip: {
                valueSuffix: '°C'
            }
        }]

Modified from this demo: http://www.highcharts.com/demo/combo-dual-axes.

You don't need to provide the tooltip formatter function either, but if you wanted other than the default, that is how you could access the series valueSuffix.

这篇关于Highstock / Highcharts上每条线的不同后缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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