Home Forums Chart Support Chart update on button click in Angular

Chart update on button click in Angular

Viewing 2 posts - 1 through 2 (of 2 total)
  • #32131

    Hello,
    I work with CanvasJS in Angular and I try to update a chart when a button is pressed. Firstly, in component.ts file I render the chart in ngOnInit.
    ngOnInit

    After that, in another method which is called when that button is pressed, I update the dataPoints like this: this.chart.data.dataPoints=newData and if I print these values using console.log(this.chart.data.dataPoints) the result looks suitable to be used by the chart:
    console

    But the chart is not updated and looks like this.
    empty-chart

    I also tried to call again this.chart.render() after the dataPoints update, but it doesn’t work.
    Could you please help me with this issue?

    Thank you,
    Raluca

    #32141

    Raluca,

    In order to update chart, you need to either change chart-options and call render or use set method. In your case, updating dataPoints through chart-options seems to be working fine. Please take a look at this updated stackblitz code.

    Considering this as duplicate of Chart update on button click in Angular, hence closing the same.


    Vishwas R
    Team CanvasJS

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

You must be logged in to reply to this topic.