luckasx
luckasx

Reputation: 369

highcharts column stack label

I want to show a stacklabel with data coming from a json file, something similar to this. http://jsfiddle.net/prJjY/183/

my code...

 yAxis: {
            title: {text:'%'},
            stackLabels: {
                style: {color: 'black'},
                enabled:true,
                formatter: function() {
                    console.log(this.axis.series[0].data);
                    return (this.axis.series[0].yData[this.y]) + '%';
                }

            }},

and my json file...

[{"y":4.2,"z":"0412","stack":"10a","color":"red"}...

It's a simple doubt. When I console series.data , it shows all the objects in json. I need to get the 'this' data something like.

this.axis.series[0].data[this].stack);

but this don't work, if I put 0 instead this,

    this.axis.series[0].data[0]  
//it works (without stack part) with stack part i got a '...data[0] is undefined'

In this way I'll get always data from zero object.

What is missing to my code work?

After the first answer I did this ...

var temp = this.axis.series[0].data[this.x];

for(var propertyName in temp) {
     console.log(temp["stacko"]); //inside the for it works
;}
console.log(temp["stacko"]); //outside the for I get Undefined

Why? :'(

Upvotes: 0

Views: 578

Answers (2)

Parley Hammon
Parley Hammon

Reputation: 27

Even though Pawel Fus's answer should work, it turns out that you have to go through options to get to the data..

like so,

this.axis.series[0].options.data[this.x].stack

Upvotes: 1

Paweł Fus
Paweł Fus

Reputation: 45079

I think that problem is you are using this as reference but you should use this.x instead:

this.axis.series[0].data[this.x].stack);

Upvotes: 0

Related Questions