Chartist-js: Refresh Chartist JS line chart

Created on 15 Sep 2017  路  2Comments  路  Source: gionkunz/chartist-js

Hi,
I'm just a beginner in JavaScript and I am using the basic line graphing library for my graph, currently the graph refreshes when I refresh the page, how ever I would like the graph to refresh using a javascript timer, does anyone know how to do this?
this is very important to me, your help would be much appreciated
thanks
Ben

Most helpful comment

You can use the update() function, documented here, to do this and tie it to a timer function. I don't believe this is the most elegant way to go about it, but it's the clearest way for those who aren't familiar with JavaScript APIs.

Example:

window.setTimeout(timerFunction, 3000); // Generic timer function called after 3 seconds
var myChart = new Chartist.Line(. . .); // The variable you used to create the chart
function timerFunction() {
    var newData = {"data1":"value1", "data2":"value2"}; // Make sure this matches the format of your original data
    myChart.update(newData);
};

You can also use timers within the Chartist API for more complex functionality such as delayed animations.

All 2 comments

You can use the update() function, documented here, to do this and tie it to a timer function. I don't believe this is the most elegant way to go about it, but it's the clearest way for those who aren't familiar with JavaScript APIs.

Example:

window.setTimeout(timerFunction, 3000); // Generic timer function called after 3 seconds
var myChart = new Chartist.Line(. . .); // The variable you used to create the chart
function timerFunction() {
    var newData = {"data1":"value1", "data2":"value2"}; // Make sure this matches the format of your original data
    myChart.update(newData);
};

You can also use timers within the Chartist API for more complex functionality such as delayed animations.

Thanks @KinnaT

Was this page helpful?
0 / 5 - 0 ratings

Related issues

denisvolokh picture denisvolokh  路  4Comments

gsklee picture gsklee  路  4Comments

bluepineventures picture bluepineventures  路  4Comments

FabienPapet picture FabienPapet  路  4Comments

ShlomoRosenheimer picture ShlomoRosenheimer  路  3Comments