Alexandre
Alexandre

Reputation: 59

Updating data with Highcharts alters initial set

I am drawing a chart using Highcharts, with my data passed to javascript as data attribute, and this works perfectly fine.

I want to be able to change the data, what I am doing like that :

chart.highcharts().series[0].setData(chart.data().secondset, true);

chart being properly defined, this works fine as well.

Then, if I try to go back to my initial data using the exact same code :

chart.highcharts().series[0].setData(chart.data().firstset, true);

it does not work, and it seems like my initial data has disappeared, so Highcharts would alter my initial data.

Here is the fiddle: http://jsfiddle.net/8zwL0cv3/1/

Thanks for your help

Upvotes: 0

Views: 50

Answers (2)

Sebastian Bochan
Sebastian Bochan

Reputation: 37578

You need to use $.extend to create a copy of data. In your case you use references, so first value is incorrect.

$.extend([],chart.data().firstset)

Example: http://jsfiddle.net/8zwL0cv3/2/

Upvotes: 0

depperm
depperm

Reputation: 10746

Noticing that the firstset changed the format I changed

chart.data().firstset

to

eval(chart.attr('data-secondset'))

working example here

Upvotes: 1

Related Questions