Auto Update of this ChartJS ScriptWhat's the easiest way to call a function every 5 seconds in jQuery?When is a CDATA section necessary within a script tag?Why don't self-closing script elements work?Where should I put <script> tags in HTML markup?How to auto-reload files in Node.js?Updating address bar with new URL without hash or reloading the pageExplanation of <script type = “text/template”> … </script>Sending command line arguments to npm scriptHow do I update each dependency in package.json to the latest version?Why is my chart.js showing datasets one after another rather than together?Not able to navigate to other page in react native
Does a creature that is immune to a condition still make a saving throw?
A non-technological, repeating, visible object in the sky, holding its position in the sky for hours
Python "triplet" dictionary?
Why is the origin of “threshold” uncertain?
Electric guitar: why such heavy pots?
What does YCWCYODFTRFDTY mean?
Was it really necessary for the Lunar Module to have 2 stages?
Sci-fi novel series with instant travel between planets through gates. A river runs through the gates
Does jamais mean always or never in this context?
Confused by notation of atomic number Z and mass number A on periodic table of elements
Can fracking help reduce CO2?
What are the spoon bit of a spoon and fork bit of a fork called?
What is the strongest case that can be made in favour of the UK regaining some control over fishing policy after Brexit?
Is thermodynamics only applicable to systems in equilibrium?
When India mathematicians did know Euclid's Elements?
Lock in SQL Server and Oracle
How does a Swashbuckler rogue "fight with two weapons while safely darting away"?
Can a creature tell when it has been affected by a Divination wizard's Portent?
Why is current rating for multicore cable lower than single core with the same cross section?
Advice on laptop battery life
Where does the labelling of extrinsic semiconductors as "n" and "p" come from?
Binary Numbers Magic Trick
Why do Ichisongas hate elephants and hippos?
Do I have to worry about players making “bad” choices on level up?
Auto Update of this ChartJS Script
What's the easiest way to call a function every 5 seconds in jQuery?When is a CDATA section necessary within a script tag?Why don't self-closing script elements work?Where should I put <script> tags in HTML markup?How to auto-reload files in Node.js?Updating address bar with new URL without hash or reloading the pageExplanation of <script type = “text/template”> … </script>Sending command line arguments to npm scriptHow do I update each dependency in package.json to the latest version?Why is my chart.js showing datasets one after another rather than together?Not able to navigate to other page in react native
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have received this piece of code to generate a chart based on data pulled from "data.php". The chart renders fine without any issues. I cannot seem to get it updating each 5 seconds.
I tried auto refreshing the whole page, but this does not seem to be productive, since you will have to scroll back down to the chart.
$(document).ready(function ()
/**
* call the data.php file to fetch the result from db table.
*/
$.ajax(
url: "http://xx.xx.xx.xx/link/going2/data.php",
type: "GET",
success: function (data)
console.log(data);
var VALUE =
iface1: [],
iface2: [],
iface3: [],
iface4: [],
iface5: [],
iface6: []
;
var len = data.length;
for (var i = 0; i < len; i++)
if (data[i].INTERFACE == "iface1")
VALUE.iface1.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface2")
VALUE.iface2.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface3")
VALUE.iface3.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface4")
VALUE.iface4.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface5")
VALUE.iface5.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface6")
VALUE.iface6.push(data[i].VALUE);
//get canvas
var t = new Date();
var ctx = $("#line-chartcanvas");
var data =
labels: [ (Removed to make code shorter)],
datasets: [
label: "cable-upstream 1/0.0",
data: VALUE.iface1,
backgroundColor: 'rgba(0, 0, 255, 1.0)',
borderColor: 'rgba(0, 0, 255, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/1.0",
data: VALUE.iface2,
backgroundColor: 'rgba(0, 128, 0, 1.0)',
borderColor: 'rgba(0, 128, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/2.0",
data: VALUE.iface3,
backgroundColor: 'rgba(255, 0, 0, 1.0)',
borderColor: 'rgba(255, 0, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/12.0",
data: VALUE.iface4,
backgroundColor: 'rgba(128, 0, 0, 1.0)',
borderColor: 'rgba(128, 0, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/13.0",
data: VALUE.iface5,
backgroundColor: 'rgba(0, 0, 0, 1.0)',
borderColor: 'rgba(0, 0, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/14.0",
data: VALUE.iface6,
backgroundColor: 'rgba(128, 0, 128, 1.0)',
borderColor: 'rgba(128, 0, 128, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
, ]
;
var options =
animation: false,
responsive: true,
title:
display: true,
position: "top",
text: "Service Group 1",
fontSize: 18,
fontColor: "#111"
,
legend:
display: true,
position: "bottom"
,
scales:
yAxes: [
ticks:
max: 30,
min: 15,
stepSize: 0.5,
callback: function (value, index, values)
return value + " dBmV";
,
scaleLabel:
display: true,
labelString: 'Signal to Noise'
]
;
var chart = new Chart(ctx,
type: "line",
data: data,
options: options
);
,
error: function (data)
console.log(data);
);
);
I expect this chart refreshing each 5 seconds (not refreshing the whole page)
javascript
add a comment |
I have received this piece of code to generate a chart based on data pulled from "data.php". The chart renders fine without any issues. I cannot seem to get it updating each 5 seconds.
I tried auto refreshing the whole page, but this does not seem to be productive, since you will have to scroll back down to the chart.
$(document).ready(function ()
/**
* call the data.php file to fetch the result from db table.
*/
$.ajax(
url: "http://xx.xx.xx.xx/link/going2/data.php",
type: "GET",
success: function (data)
console.log(data);
var VALUE =
iface1: [],
iface2: [],
iface3: [],
iface4: [],
iface5: [],
iface6: []
;
var len = data.length;
for (var i = 0; i < len; i++)
if (data[i].INTERFACE == "iface1")
VALUE.iface1.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface2")
VALUE.iface2.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface3")
VALUE.iface3.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface4")
VALUE.iface4.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface5")
VALUE.iface5.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface6")
VALUE.iface6.push(data[i].VALUE);
//get canvas
var t = new Date();
var ctx = $("#line-chartcanvas");
var data =
labels: [ (Removed to make code shorter)],
datasets: [
label: "cable-upstream 1/0.0",
data: VALUE.iface1,
backgroundColor: 'rgba(0, 0, 255, 1.0)',
borderColor: 'rgba(0, 0, 255, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/1.0",
data: VALUE.iface2,
backgroundColor: 'rgba(0, 128, 0, 1.0)',
borderColor: 'rgba(0, 128, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/2.0",
data: VALUE.iface3,
backgroundColor: 'rgba(255, 0, 0, 1.0)',
borderColor: 'rgba(255, 0, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/12.0",
data: VALUE.iface4,
backgroundColor: 'rgba(128, 0, 0, 1.0)',
borderColor: 'rgba(128, 0, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/13.0",
data: VALUE.iface5,
backgroundColor: 'rgba(0, 0, 0, 1.0)',
borderColor: 'rgba(0, 0, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/14.0",
data: VALUE.iface6,
backgroundColor: 'rgba(128, 0, 128, 1.0)',
borderColor: 'rgba(128, 0, 128, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
, ]
;
var options =
animation: false,
responsive: true,
title:
display: true,
position: "top",
text: "Service Group 1",
fontSize: 18,
fontColor: "#111"
,
legend:
display: true,
position: "bottom"
,
scales:
yAxes: [
ticks:
max: 30,
min: 15,
stepSize: 0.5,
callback: function (value, index, values)
return value + " dBmV";
,
scaleLabel:
display: true,
labelString: 'Signal to Noise'
]
;
var chart = new Chart(ctx,
type: "line",
data: data,
options: options
);
,
error: function (data)
console.log(data);
);
);
I expect this chart refreshing each 5 seconds (not refreshing the whole page)
javascript
1
Create a timer with setInterval
– davmich
Mar 22 at 19:27
Why don't you update your chart after a change on thehttp://xx.xx.xx.xx/link/going2/data.php
has been made, so you don't consume so may request calls.
– Angel Roma
Mar 22 at 21:02
There is a Cron job running each 5 seconds upon activation, this cron job polls snmp details from a device and dumps them in SQL (for history purposes), and uses 1 table to keep last 606 records to populate this table each 5 seconds. SetInterval interval will loop perfectly, but it only creates a new <div> </div> with the chart info and does not eliminate the old data. after 2 or 3 minutes running the chart will start glitching out once you put mouse over (around 30 charts stacked). I am looking for a way that the script can update but not keep creating more <div></div>'s
– Juliandro Soree
Mar 22 at 21:20
You need to chart.destroy() the previous chart before you can create new Chart(), otherwise it will glitch. chartjs.org/docs/latest/developers/api.html
– Iskandar Reza Razali
Mar 22 at 22:09
add a comment |
I have received this piece of code to generate a chart based on data pulled from "data.php". The chart renders fine without any issues. I cannot seem to get it updating each 5 seconds.
I tried auto refreshing the whole page, but this does not seem to be productive, since you will have to scroll back down to the chart.
$(document).ready(function ()
/**
* call the data.php file to fetch the result from db table.
*/
$.ajax(
url: "http://xx.xx.xx.xx/link/going2/data.php",
type: "GET",
success: function (data)
console.log(data);
var VALUE =
iface1: [],
iface2: [],
iface3: [],
iface4: [],
iface5: [],
iface6: []
;
var len = data.length;
for (var i = 0; i < len; i++)
if (data[i].INTERFACE == "iface1")
VALUE.iface1.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface2")
VALUE.iface2.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface3")
VALUE.iface3.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface4")
VALUE.iface4.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface5")
VALUE.iface5.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface6")
VALUE.iface6.push(data[i].VALUE);
//get canvas
var t = new Date();
var ctx = $("#line-chartcanvas");
var data =
labels: [ (Removed to make code shorter)],
datasets: [
label: "cable-upstream 1/0.0",
data: VALUE.iface1,
backgroundColor: 'rgba(0, 0, 255, 1.0)',
borderColor: 'rgba(0, 0, 255, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/1.0",
data: VALUE.iface2,
backgroundColor: 'rgba(0, 128, 0, 1.0)',
borderColor: 'rgba(0, 128, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/2.0",
data: VALUE.iface3,
backgroundColor: 'rgba(255, 0, 0, 1.0)',
borderColor: 'rgba(255, 0, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/12.0",
data: VALUE.iface4,
backgroundColor: 'rgba(128, 0, 0, 1.0)',
borderColor: 'rgba(128, 0, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/13.0",
data: VALUE.iface5,
backgroundColor: 'rgba(0, 0, 0, 1.0)',
borderColor: 'rgba(0, 0, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/14.0",
data: VALUE.iface6,
backgroundColor: 'rgba(128, 0, 128, 1.0)',
borderColor: 'rgba(128, 0, 128, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
, ]
;
var options =
animation: false,
responsive: true,
title:
display: true,
position: "top",
text: "Service Group 1",
fontSize: 18,
fontColor: "#111"
,
legend:
display: true,
position: "bottom"
,
scales:
yAxes: [
ticks:
max: 30,
min: 15,
stepSize: 0.5,
callback: function (value, index, values)
return value + " dBmV";
,
scaleLabel:
display: true,
labelString: 'Signal to Noise'
]
;
var chart = new Chart(ctx,
type: "line",
data: data,
options: options
);
,
error: function (data)
console.log(data);
);
);
I expect this chart refreshing each 5 seconds (not refreshing the whole page)
javascript
I have received this piece of code to generate a chart based on data pulled from "data.php". The chart renders fine without any issues. I cannot seem to get it updating each 5 seconds.
I tried auto refreshing the whole page, but this does not seem to be productive, since you will have to scroll back down to the chart.
$(document).ready(function ()
/**
* call the data.php file to fetch the result from db table.
*/
$.ajax(
url: "http://xx.xx.xx.xx/link/going2/data.php",
type: "GET",
success: function (data)
console.log(data);
var VALUE =
iface1: [],
iface2: [],
iface3: [],
iface4: [],
iface5: [],
iface6: []
;
var len = data.length;
for (var i = 0; i < len; i++)
if (data[i].INTERFACE == "iface1")
VALUE.iface1.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface2")
VALUE.iface2.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface3")
VALUE.iface3.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface4")
VALUE.iface4.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface5")
VALUE.iface5.push(data[i].VALUE);
else if (data[i].INTERFACE == "iface6")
VALUE.iface6.push(data[i].VALUE);
//get canvas
var t = new Date();
var ctx = $("#line-chartcanvas");
var data =
labels: [ (Removed to make code shorter)],
datasets: [
label: "cable-upstream 1/0.0",
data: VALUE.iface1,
backgroundColor: 'rgba(0, 0, 255, 1.0)',
borderColor: 'rgba(0, 0, 255, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/1.0",
data: VALUE.iface2,
backgroundColor: 'rgba(0, 128, 0, 1.0)',
borderColor: 'rgba(0, 128, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/2.0",
data: VALUE.iface3,
backgroundColor: 'rgba(255, 0, 0, 1.0)',
borderColor: 'rgba(255, 0, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/12.0",
data: VALUE.iface4,
backgroundColor: 'rgba(128, 0, 0, 1.0)',
borderColor: 'rgba(128, 0, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/13.0",
data: VALUE.iface5,
backgroundColor: 'rgba(0, 0, 0, 1.0)',
borderColor: 'rgba(0, 0, 0, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
,
label: "cable-upstream 1/14.0",
data: VALUE.iface6,
backgroundColor: 'rgba(128, 0, 128, 1.0)',
borderColor: 'rgba(128, 0, 128, 0.5)',
fill: false,
lineTension: 0,
pointRadius: 2
, ]
;
var options =
animation: false,
responsive: true,
title:
display: true,
position: "top",
text: "Service Group 1",
fontSize: 18,
fontColor: "#111"
,
legend:
display: true,
position: "bottom"
,
scales:
yAxes: [
ticks:
max: 30,
min: 15,
stepSize: 0.5,
callback: function (value, index, values)
return value + " dBmV";
,
scaleLabel:
display: true,
labelString: 'Signal to Noise'
]
;
var chart = new Chart(ctx,
type: "line",
data: data,
options: options
);
,
error: function (data)
console.log(data);
);
);
I expect this chart refreshing each 5 seconds (not refreshing the whole page)
javascript
javascript
edited Mar 22 at 19:19
Amy
22.1k1976133
22.1k1976133
asked Mar 22 at 19:16
Juliandro SoreeJuliandro Soree
1
1
1
Create a timer with setInterval
– davmich
Mar 22 at 19:27
Why don't you update your chart after a change on thehttp://xx.xx.xx.xx/link/going2/data.php
has been made, so you don't consume so may request calls.
– Angel Roma
Mar 22 at 21:02
There is a Cron job running each 5 seconds upon activation, this cron job polls snmp details from a device and dumps them in SQL (for history purposes), and uses 1 table to keep last 606 records to populate this table each 5 seconds. SetInterval interval will loop perfectly, but it only creates a new <div> </div> with the chart info and does not eliminate the old data. after 2 or 3 minutes running the chart will start glitching out once you put mouse over (around 30 charts stacked). I am looking for a way that the script can update but not keep creating more <div></div>'s
– Juliandro Soree
Mar 22 at 21:20
You need to chart.destroy() the previous chart before you can create new Chart(), otherwise it will glitch. chartjs.org/docs/latest/developers/api.html
– Iskandar Reza Razali
Mar 22 at 22:09
add a comment |
1
Create a timer with setInterval
– davmich
Mar 22 at 19:27
Why don't you update your chart after a change on thehttp://xx.xx.xx.xx/link/going2/data.php
has been made, so you don't consume so may request calls.
– Angel Roma
Mar 22 at 21:02
There is a Cron job running each 5 seconds upon activation, this cron job polls snmp details from a device and dumps them in SQL (for history purposes), and uses 1 table to keep last 606 records to populate this table each 5 seconds. SetInterval interval will loop perfectly, but it only creates a new <div> </div> with the chart info and does not eliminate the old data. after 2 or 3 minutes running the chart will start glitching out once you put mouse over (around 30 charts stacked). I am looking for a way that the script can update but not keep creating more <div></div>'s
– Juliandro Soree
Mar 22 at 21:20
You need to chart.destroy() the previous chart before you can create new Chart(), otherwise it will glitch. chartjs.org/docs/latest/developers/api.html
– Iskandar Reza Razali
Mar 22 at 22:09
1
1
Create a timer with setInterval
– davmich
Mar 22 at 19:27
Create a timer with setInterval
– davmich
Mar 22 at 19:27
Why don't you update your chart after a change on the
http://xx.xx.xx.xx/link/going2/data.php
has been made, so you don't consume so may request calls.– Angel Roma
Mar 22 at 21:02
Why don't you update your chart after a change on the
http://xx.xx.xx.xx/link/going2/data.php
has been made, so you don't consume so may request calls.– Angel Roma
Mar 22 at 21:02
There is a Cron job running each 5 seconds upon activation, this cron job polls snmp details from a device and dumps them in SQL (for history purposes), and uses 1 table to keep last 606 records to populate this table each 5 seconds. SetInterval interval will loop perfectly, but it only creates a new <div> </div> with the chart info and does not eliminate the old data. after 2 or 3 minutes running the chart will start glitching out once you put mouse over (around 30 charts stacked). I am looking for a way that the script can update but not keep creating more <div></div>'s
– Juliandro Soree
Mar 22 at 21:20
There is a Cron job running each 5 seconds upon activation, this cron job polls snmp details from a device and dumps them in SQL (for history purposes), and uses 1 table to keep last 606 records to populate this table each 5 seconds. SetInterval interval will loop perfectly, but it only creates a new <div> </div> with the chart info and does not eliminate the old data. after 2 or 3 minutes running the chart will start glitching out once you put mouse over (around 30 charts stacked). I am looking for a way that the script can update but not keep creating more <div></div>'s
– Juliandro Soree
Mar 22 at 21:20
You need to chart.destroy() the previous chart before you can create new Chart(), otherwise it will glitch. chartjs.org/docs/latest/developers/api.html
– Iskandar Reza Razali
Mar 22 at 22:09
You need to chart.destroy() the previous chart before you can create new Chart(), otherwise it will glitch. chartjs.org/docs/latest/developers/api.html
– Iskandar Reza Razali
Mar 22 at 22:09
add a comment |
1 Answer
1
active
oldest
votes
I think you want to refresh the chart every 5 second.
so use this code :
window.setInterval(function()
/// call your function here
, 5000);
To stop the loop you can use
clearInterval()
please check this link reference
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55306430%2fauto-update-of-this-chartjs-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you want to refresh the chart every 5 second.
so use this code :
window.setInterval(function()
/// call your function here
, 5000);
To stop the loop you can use
clearInterval()
please check this link reference
add a comment |
I think you want to refresh the chart every 5 second.
so use this code :
window.setInterval(function()
/// call your function here
, 5000);
To stop the loop you can use
clearInterval()
please check this link reference
add a comment |
I think you want to refresh the chart every 5 second.
so use this code :
window.setInterval(function()
/// call your function here
, 5000);
To stop the loop you can use
clearInterval()
please check this link reference
I think you want to refresh the chart every 5 second.
so use this code :
window.setInterval(function()
/// call your function here
, 5000);
To stop the loop you can use
clearInterval()
please check this link reference
answered Mar 22 at 20:45
Razmik GhookasRazmik Ghookas
854
854
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55306430%2fauto-update-of-this-chartjs-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Create a timer with setInterval
– davmich
Mar 22 at 19:27
Why don't you update your chart after a change on the
http://xx.xx.xx.xx/link/going2/data.php
has been made, so you don't consume so may request calls.– Angel Roma
Mar 22 at 21:02
There is a Cron job running each 5 seconds upon activation, this cron job polls snmp details from a device and dumps them in SQL (for history purposes), and uses 1 table to keep last 606 records to populate this table each 5 seconds. SetInterval interval will loop perfectly, but it only creates a new <div> </div> with the chart info and does not eliminate the old data. after 2 or 3 minutes running the chart will start glitching out once you put mouse over (around 30 charts stacked). I am looking for a way that the script can update but not keep creating more <div></div>'s
– Juliandro Soree
Mar 22 at 21:20
You need to chart.destroy() the previous chart before you can create new Chart(), otherwise it will glitch. chartjs.org/docs/latest/developers/api.html
– Iskandar Reza Razali
Mar 22 at 22:09