Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add additional data to a Highcharts series for use in formatters

Tags:

highcharts

My question is exactly the same as the OP in this question:

Set Additional Data to highcharts series

But the accepted answer explains how to add additional data to the point, not the series, without saying if it's possible to do with the series or not.

I would like to be able to define a series like:

series: [
    {"hasCustomFlag": true, "name": "s1", "data": [...]},
    {"hasCustomFlag": false, "name": "s2", "data": [...]},
]

and be able to use point.series.hasCustomFlag inside of a formatting function. Is this possible?

I don't want to put the data on the point level, because that means I'd have to duplicate the data far too many times.

like image 575
Eli Stevens Avatar asked Jan 06 '12 01:01

Eli Stevens


2 Answers

Yes this is possible, the extra configuration properties is located under the options property (this.series refers to the series instance, not the configuration objects). See the reference here and scroll down to properties section.

So instead use this line in the formatter:

if (this.series.options.hasCustomFlag) { ... } 

Full example on jsfiddle

like image 184
eolsson Avatar answered Sep 24 '22 18:09

eolsson


This appears to have been revised with later iterations of HighCharts/HighStocks. The jsfiddle example no longer works. Using the "this.series.options.hasCustomFlag" syntax results in "undefined". The debugger shows the data I'm looking for is in "this.series.userOptions.data" - an unsorted very large array, but the entire series is there - not the specific record data you normally get with this.x or this.y.

like image 29
Dick Avatar answered Sep 23 '22 18:09

Dick