Home forums Using CanvasJS Chart always rendering, unable to change data.

This topic contains 1 reply, has 2 voices, and was last updated by  Suyash Singh 8 months, 3 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #19218

    wtf
    Member

    Despite the fact that I am not calling the render function, the charts always appear and cannot be changed by changing the data and re-rendering.

    Codepen example:

    #19234

    Suyash Singh
    Participant

    @wtf,

    Despite the fact that I am not calling the render function

    The chart is getting rendered as change method is called which in turn calls chart.render().

    function change() {   
        newTitle = "is going on";
        chart.render(); // chart.render() gets called inside change
    }
    change(); // Call to the change method

    Please take a look at this MDN Page on Javascript Functions.

    cannot be changed by changing the data and re-rendering.

    The title is not being updated as chart options are not updated within change method instead, you are updating newTitle. You can use set method to update the chart title. Please add the following line after chart.render() method in change();
    chart.title.set("text", newTitle);

    You can take a look at this Documentation Link on set() for more info.

    Also, we noticed that you haven’t set the dataPoints properly. dataPoints should be an array which is number in your case.
    dataPoints: 0 // incorrect, should be an []

    The chart should work fine after making all these changes.
    ___
    Suyash Singh
    Team CanvasJS

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

You must be logged in to reply to this topic.