Home forums Report Bugs Zooming on graph changes it to another graph. Reply To: Zooming on graph changes it to another graph.

#17278

cgar
Member

Thank you so much @indranil!

I was really stumped at this one. Tried all sorts of things with no luck. It was so strange and annoying to me that it worked fine when messily duplicated three times in each chart constructor but not neatly one time from a variable.

Your links and jsfiddle were very helpful. Once I knew I needed to somehow copy the object without the reference. Finding a solution in a compact form, which I was now obsessive about, took no time at all lol.

This is what I’ve ended up doing:

Before the construction of each chart, I simply do:
var defaults_<name> = jQuery.extend(true, {}, chart_defaults);
And then I construct with defaults_<name> instead of chart_defaults.

According to this question and answer on stack overflow where I learned the function It’s known as deep cloning a javascript object.

So now any additions or changes stay isolated to that chart as they should. Yey! =)

Full page’s code for anyone that may be interested in more context to the solution.