Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show specific series values in the stack label using highcharts

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!

like image 346
yoshi0423 Avatar asked Dec 08 '12 02:12

yoshi0423


1 Answers

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/

like image 59
cubbuk Avatar answered Nov 07 '22 06:11

cubbuk