Skip to content
Advertisement

Dynamically change ChartJS Line Chart using Jquery

I’m receiving 3 arrays from server as a response and I’m trying to create a line chart using ChartJS. The line chart turns out to be fine when I feed in the static values but it doesn’t reflect the changes when new data is passed from the server.

JavaScript

The arrays after being populated by server response looks like this:
enter image description here

When my application starts, the chart looks like this (as arrays are empty):

enter image description here

I’ve tried doing “myChart.update()” in the success part of my ajax request, but that is not proving to be successful.

The output should look like this and change dynamically when server responds with different values.

enter image description here

Advertisement

Answer

Defining a function and calling it after “success” part of my ajax request has resolved the problem for me. So in my previous code, in place of

JavaScript

I’m calling this function now.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement