Home Forums Report Bugs Zooming on graph changes it to another graph.

Zooming on graph changes it to another graph.

Viewing 4 posts - 1 through 4 (of 4 total)
  • #17272

    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.

    #17275

    @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

    • This reply was modified 6 years, 5 months ago by Indranil.
    #17278

    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.

    #17324

    When you make the selected on a chart, did you get that zoom reflected in the second chart?

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.