使用highcharts在堆叠标签中显示特定的系列值 [英] Show specific series values in the stack label using highcharts

查看:209
本文介绍了使用highcharts在堆叠标签中显示特定的系列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我正在处理的内容: http://jsfiddle.net/josip0423/prJjY/171 /



过去几个小时,我一直在摔跤而没有得到任何地方。我对javascript很陌生,今天刚刚发现了高分。



默认情况下,堆栈标签显示两个系列的总数(this.total)。我想要做的是显示其中一个系列的百分比(完整系列的值/ this.total * 100)。

我无法弄清楚如何提取完整系列的值。

  yAxis:{
stackLabels:{
样式:{
color:'black'
},
enabled:true,
formatter:function(){

** return this.total **

}
}
}

所以最后,我的图看起来完全一样,除了每列上方的标签将显示完整系列的百分比。



预先感谢! p>

解决方案

您可以通过从格式化程序回调函数获取系列对象来完成此操作。

  stackLabels:{
style:{
color:'black'
},
enabled:true,
formatter:function(){
return(this.axis.series [1] .yData [this.x] / this.total * 100).toPrecision(2)+'%';


$ / code $ / pre

下面是你的情况下的jsfiddle:


http://jsfiddle.net/prJjY/183/



Here's what I'm working with: http://jsfiddle.net/josip0423/prJjY/171/

I've been wrestling with this for the past few hours without getting anywhere. I'm very new to javascript, and just found highcharts today.

By default the stack label shows the total of both series (this.total). What I want to do is show the percent of one of the series (value of "Complete" series / this.total * 100).

I can't figure out how to extract the value for the "Complete" series.

yAxis: {
            stackLabels: {
                style: {
                    color: 'black'
                },
                enabled: true,
                formatter: function() {

                    **return this.total**

                }
            }
        }

So in the end, my graph looks exactly the same, except the labels above each column will show the percent for the "Complete" series.

Thanks in advance!

解决方案

You can do that by getting the series object from the formatter callback function.

stackLabels: {
              style: {
                         color: 'black'
                     },
                     enabled: true,
                     formatter: function() {   
                        return (this.axis.series[1].yData[this.x] / this.total * 100).toPrecision(2) + '%';                                
                    }
            }

Here is the jsfiddle for your case:

http://jsfiddle.net/prJjY/183/

这篇关于使用highcharts在堆叠标签中显示特定的系列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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