user393267
user393267

Reputation:

Retrieve the content of series data [] in Highcharts, after rendering the chart?

I would like to add in the click event, a line of code that when I click on the chart, grab the content of the data [] in its series, to save it in a variable for future use.

Which one is the syntax to do so? this.chart.series didn't work.

I am planning to pass this to another chart, as data:

This is what I have so far; tried with get() also but I still get undefined errors

chart: {
    renderTo: 'chart',
    events: {
        click:function(event){
            extracteddata=this.chart.get('mainseries');
        }        
    },
}

When I print out in console; the only thing that I get is "this"; which return me the whole chart object including everything inside.

Tried so far with

this.series.option.data
this.data
this.series

And neither return the content of the array. I have printed out "this" and I can clearly see the series.data array which is correctly populated.

Upvotes: 0

Views: 2741

Answers (1)

Mark
Mark

Reputation: 108557

this.series is an array of series objects, so assuming you want the first series, use:

events: {
    click: function (event) {
        var someData = this.series[0].data;
    }
}

someData here is an array of point objects. If you want just numbers use

this.series[0].yData

and/or

this.series[0].xData

Upvotes: 1

Related Questions