Show specific series values in the stack label usi

2019-04-09 03:22发布

问题:

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!

回答1:

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/