You must be logged in to post your query.
Home › Forums › Report Bugs › Zooming on graph changes it to another graph.
Tagged: AJAX, Clone, csv, jquery, object, zoom
I have a strange problem on a sensor data from csv page I’ve put together.
It has 3 graphs. Temperature, Humidity and Pressure.
Whenever I zoom on either temperature or humidity it zooms to where I wanted but it also suddenly inexplicably changes itself into another pressure graph.
Here is my jsfiddle: http://jsfiddle.net/wqcevrdb/1/
I’m not sure if this is just me again but I can’t see anything wrong with the code.
@cgar,
In JavaScript, Objects are passed as References. So, changes made to a title.text will be reflected across all charts as same object is passed as chart-options for all. Using separate options for every chart would work fine in your case.
Please take a look at the following StackOverflow links- Javascript by reference vs. by value Is JavaScript a pass-by-reference or pass-by-value?
Also, please take a look at this updated jsfiddle.
___________ Indranil Deo, Team CanvasJS
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.
var defaults_<name> = jQuery.extend(true, {}, 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.
When you make the selected on a chart, did you get that zoom reflected in the second chart?
You must be logged in to reply to this topic. Login/Register