Reputation: 59
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
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