Count up values in Chart JS2019 Community Moderator ElectionWhich “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?Set a default parameter value for a JavaScript functionHow can I get query string values in JavaScript?Sort array of objects by string property valueCopy array by valueHow to change color of labels in bar chart using chart.jscustom bar at specific position chart jsData label over stacked bar chartChart.js max legend heightUpdate yAxes when changing xAxes min and max for ChartJS

Are there other characters in the Star Wars universe who had damaged bodies and needed to wear an outfit like Darth Vader?

I can't die. Who am I?

Has Wakanda ever accepted refugees?

Reason why dimensional travelling would be restricted

Formatting a table to look nice

GDAL GetGeoTransform Documentation -- Is there an oversight, or what am I misunderstanding?

Where is the fallacy here?

Sometimes a banana is just a banana

Find maximum of the output from reduce

Why is it "take a leak?"

Correct physics behind the colors on CD (compact disc)?

Canadian citizen, on US no-fly list. What can I do in order to be allowed on flights which go through US airspace?

Specific Chinese carabiner QA?

Where is this quote about overcoming the impossible said in "Interstellar"?

How can I highlight parts in a screenshot

It doesn't matter the side you see it

I encountered my boss during an on-site interview at another company. Should I bring it up when seeing him next time?

How can I handle a player who pre-plans arguments about my rulings on RAW?

Was it really inappropriate to write a pull request for the company I interviewed with?

Wardrobe above a wall with fuse boxes

Why won't the strings command stop?

How can I be pwned if I'm not registered on the compromised site?

An Undercover Army

PTIJ: Should I stay away from my computer?



Count up values in Chart JS



2019 Community Moderator ElectionWhich “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?Set a default parameter value for a JavaScript functionHow can I get query string values in JavaScript?Sort array of objects by string property valueCopy array by valueHow to change color of labels in bar chart using chart.jscustom bar at specific position chart jsData label over stacked bar chartChart.js max legend heightUpdate yAxes when changing xAxes min and max for ChartJS










2















how do I make the values in Chart JS update as the bar progresses?



For example, I want the values for each bar to start at 0 and count up to there value, stopping when the bar has reached it's height.



At the moment, it just displays it's full value upon animation start (when the page loads)



Chart JS docs:
https://www.chartjs.org/



Here is a plugin I found:
https://emn178.github.io/chartjs-plugin-labels/samples/demo/



Here is a JS Fiddle (ignore the shaking!)
https://jsfiddle.net/8uehq5xr/



<!doctype html>
<html>

<head>
<title>Horizontal Bar Chart</title>
<script src="../../node_modules/chart.js/dist/Chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.7.3/dist/Chart.min.js">
</script>
<script src="https://cdn.jsdelivr.net/gh/emn178/chartjs-plugin-
labels/src/chartjs-plugin-labels.js"></script>
</head>

<body>
<canvas id="bar-chart" width="800" height="450"></canvas>

<div id="value">100</div>

<Script>


// Bar chart
new Chart(document.getElementById("bar-chart"),
type: 'bar',
data:
labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],

datasets: [

label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
data: [2478,5267,734,784,433]

]
,



options:

plugins:
labels:

render: 'value',

fontSize: 20,

,
scales:
xAxes: [
display: false
],
yAxes: [
display: false
],
,
tooltips: enabled: true,
hover: animationDuration: 1,


);

</script>
</body>

</html>









share|improve this question






















  • try to draw the chart with ajax. try to redraw the chart after ajax callbacks

    – rejin
    20 hours ago















2















how do I make the values in Chart JS update as the bar progresses?



For example, I want the values for each bar to start at 0 and count up to there value, stopping when the bar has reached it's height.



At the moment, it just displays it's full value upon animation start (when the page loads)



Chart JS docs:
https://www.chartjs.org/



Here is a plugin I found:
https://emn178.github.io/chartjs-plugin-labels/samples/demo/



Here is a JS Fiddle (ignore the shaking!)
https://jsfiddle.net/8uehq5xr/



<!doctype html>
<html>

<head>
<title>Horizontal Bar Chart</title>
<script src="../../node_modules/chart.js/dist/Chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.7.3/dist/Chart.min.js">
</script>
<script src="https://cdn.jsdelivr.net/gh/emn178/chartjs-plugin-
labels/src/chartjs-plugin-labels.js"></script>
</head>

<body>
<canvas id="bar-chart" width="800" height="450"></canvas>

<div id="value">100</div>

<Script>


// Bar chart
new Chart(document.getElementById("bar-chart"),
type: 'bar',
data:
labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],

datasets: [

label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
data: [2478,5267,734,784,433]

]
,



options:

plugins:
labels:

render: 'value',

fontSize: 20,

,
scales:
xAxes: [
display: false
],
yAxes: [
display: false
],
,
tooltips: enabled: true,
hover: animationDuration: 1,


);

</script>
</body>

</html>









share|improve this question






















  • try to draw the chart with ajax. try to redraw the chart after ajax callbacks

    – rejin
    20 hours ago













2












2








2








how do I make the values in Chart JS update as the bar progresses?



For example, I want the values for each bar to start at 0 and count up to there value, stopping when the bar has reached it's height.



At the moment, it just displays it's full value upon animation start (when the page loads)



Chart JS docs:
https://www.chartjs.org/



Here is a plugin I found:
https://emn178.github.io/chartjs-plugin-labels/samples/demo/



Here is a JS Fiddle (ignore the shaking!)
https://jsfiddle.net/8uehq5xr/



<!doctype html>
<html>

<head>
<title>Horizontal Bar Chart</title>
<script src="../../node_modules/chart.js/dist/Chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.7.3/dist/Chart.min.js">
</script>
<script src="https://cdn.jsdelivr.net/gh/emn178/chartjs-plugin-
labels/src/chartjs-plugin-labels.js"></script>
</head>

<body>
<canvas id="bar-chart" width="800" height="450"></canvas>

<div id="value">100</div>

<Script>


// Bar chart
new Chart(document.getElementById("bar-chart"),
type: 'bar',
data:
labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],

datasets: [

label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
data: [2478,5267,734,784,433]

]
,



options:

plugins:
labels:

render: 'value',

fontSize: 20,

,
scales:
xAxes: [
display: false
],
yAxes: [
display: false
],
,
tooltips: enabled: true,
hover: animationDuration: 1,


);

</script>
</body>

</html>









share|improve this question














how do I make the values in Chart JS update as the bar progresses?



For example, I want the values for each bar to start at 0 and count up to there value, stopping when the bar has reached it's height.



At the moment, it just displays it's full value upon animation start (when the page loads)



Chart JS docs:
https://www.chartjs.org/



Here is a plugin I found:
https://emn178.github.io/chartjs-plugin-labels/samples/demo/



Here is a JS Fiddle (ignore the shaking!)
https://jsfiddle.net/8uehq5xr/



<!doctype html>
<html>

<head>
<title>Horizontal Bar Chart</title>
<script src="../../node_modules/chart.js/dist/Chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.7.3/dist/Chart.min.js">
</script>
<script src="https://cdn.jsdelivr.net/gh/emn178/chartjs-plugin-
labels/src/chartjs-plugin-labels.js"></script>
</head>

<body>
<canvas id="bar-chart" width="800" height="450"></canvas>

<div id="value">100</div>

<Script>


// Bar chart
new Chart(document.getElementById("bar-chart"),
type: 'bar',
data:
labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],

datasets: [

label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
data: [2478,5267,734,784,433]

]
,



options:

plugins:
labels:

render: 'value',

fontSize: 20,

,
scales:
xAxes: [
display: false
],
yAxes: [
display: false
],
,
tooltips: enabled: true,
hover: animationDuration: 1,


);

</script>
</body>

</html>






javascript chart.js






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 21 hours ago









R.DixonR.Dixon

113




113












  • try to draw the chart with ajax. try to redraw the chart after ajax callbacks

    – rejin
    20 hours ago

















  • try to draw the chart with ajax. try to redraw the chart after ajax callbacks

    – rejin
    20 hours ago
















try to draw the chart with ajax. try to redraw the chart after ajax callbacks

– rejin
20 hours ago





try to draw the chart with ajax. try to redraw the chart after ajax callbacks

– rejin
20 hours ago












1 Answer
1






active

oldest

votes


















1














I assume you would like something like a fast counter synchronized with chart drawing, can't you do it with just a for loop refreshing data given to chart.js until you reach their real value ?



No need for a plugin if it's a that small improvement you need



Example:



final data is [2478,5267,734,784,433]
initial data is [0, 0, 0, 0, 0]



1°) set an interval incrementing data of 1/10 of their value by example, each 200ms



-> after 200ms you now have [247, 526, 73, 78, 43]



2°) cancel interval once you reached final data



You can then play with interval and increment steps (1/100 in stead of 1/10 by example)



Here is a workaround (but I bet you block with chart drawing ?)



const currentData = [0,0,0,0,0];
const finalData = [2478,5267,734,784,433];
const stepTick = 0.1;
let stepNumber = 1;

const redrawingAfter1Step = setInterval(() =>
for(let i = 0; i < currentData.length; i++)
currentData[i] = stepTick * stepNumber * finalData[i];


drawChart(currentData);

if ((stepNumber * stepTick) === 1)
clearInterval(redrawingAfter1Step);


stepNumber++;

, 500);





share|improve this answer










New contributor




Antoine Gautrain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Yes, that was my thought - but I don't know how to do that in the code

    – R.Dixon
    20 hours ago











  • I've added a JS Fiddle in the OP above. Try adding it there.

    – R.Dixon
    19 hours ago










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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55020228%2fcount-up-values-in-chart-js%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









1














I assume you would like something like a fast counter synchronized with chart drawing, can't you do it with just a for loop refreshing data given to chart.js until you reach their real value ?



No need for a plugin if it's a that small improvement you need



Example:



final data is [2478,5267,734,784,433]
initial data is [0, 0, 0, 0, 0]



1°) set an interval incrementing data of 1/10 of their value by example, each 200ms



-> after 200ms you now have [247, 526, 73, 78, 43]



2°) cancel interval once you reached final data



You can then play with interval and increment steps (1/100 in stead of 1/10 by example)



Here is a workaround (but I bet you block with chart drawing ?)



const currentData = [0,0,0,0,0];
const finalData = [2478,5267,734,784,433];
const stepTick = 0.1;
let stepNumber = 1;

const redrawingAfter1Step = setInterval(() =>
for(let i = 0; i < currentData.length; i++)
currentData[i] = stepTick * stepNumber * finalData[i];


drawChart(currentData);

if ((stepNumber * stepTick) === 1)
clearInterval(redrawingAfter1Step);


stepNumber++;

, 500);





share|improve this answer










New contributor




Antoine Gautrain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Yes, that was my thought - but I don't know how to do that in the code

    – R.Dixon
    20 hours ago











  • I've added a JS Fiddle in the OP above. Try adding it there.

    – R.Dixon
    19 hours ago















1














I assume you would like something like a fast counter synchronized with chart drawing, can't you do it with just a for loop refreshing data given to chart.js until you reach their real value ?



No need for a plugin if it's a that small improvement you need



Example:



final data is [2478,5267,734,784,433]
initial data is [0, 0, 0, 0, 0]



1°) set an interval incrementing data of 1/10 of their value by example, each 200ms



-> after 200ms you now have [247, 526, 73, 78, 43]



2°) cancel interval once you reached final data



You can then play with interval and increment steps (1/100 in stead of 1/10 by example)



Here is a workaround (but I bet you block with chart drawing ?)



const currentData = [0,0,0,0,0];
const finalData = [2478,5267,734,784,433];
const stepTick = 0.1;
let stepNumber = 1;

const redrawingAfter1Step = setInterval(() =>
for(let i = 0; i < currentData.length; i++)
currentData[i] = stepTick * stepNumber * finalData[i];


drawChart(currentData);

if ((stepNumber * stepTick) === 1)
clearInterval(redrawingAfter1Step);


stepNumber++;

, 500);





share|improve this answer










New contributor




Antoine Gautrain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Yes, that was my thought - but I don't know how to do that in the code

    – R.Dixon
    20 hours ago











  • I've added a JS Fiddle in the OP above. Try adding it there.

    – R.Dixon
    19 hours ago













1












1








1







I assume you would like something like a fast counter synchronized with chart drawing, can't you do it with just a for loop refreshing data given to chart.js until you reach their real value ?



No need for a plugin if it's a that small improvement you need



Example:



final data is [2478,5267,734,784,433]
initial data is [0, 0, 0, 0, 0]



1°) set an interval incrementing data of 1/10 of their value by example, each 200ms



-> after 200ms you now have [247, 526, 73, 78, 43]



2°) cancel interval once you reached final data



You can then play with interval and increment steps (1/100 in stead of 1/10 by example)



Here is a workaround (but I bet you block with chart drawing ?)



const currentData = [0,0,0,0,0];
const finalData = [2478,5267,734,784,433];
const stepTick = 0.1;
let stepNumber = 1;

const redrawingAfter1Step = setInterval(() =>
for(let i = 0; i < currentData.length; i++)
currentData[i] = stepTick * stepNumber * finalData[i];


drawChart(currentData);

if ((stepNumber * stepTick) === 1)
clearInterval(redrawingAfter1Step);


stepNumber++;

, 500);





share|improve this answer










New contributor




Antoine Gautrain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










I assume you would like something like a fast counter synchronized with chart drawing, can't you do it with just a for loop refreshing data given to chart.js until you reach their real value ?



No need for a plugin if it's a that small improvement you need



Example:



final data is [2478,5267,734,784,433]
initial data is [0, 0, 0, 0, 0]



1°) set an interval incrementing data of 1/10 of their value by example, each 200ms



-> after 200ms you now have [247, 526, 73, 78, 43]



2°) cancel interval once you reached final data



You can then play with interval and increment steps (1/100 in stead of 1/10 by example)



Here is a workaround (but I bet you block with chart drawing ?)



const currentData = [0,0,0,0,0];
const finalData = [2478,5267,734,784,433];
const stepTick = 0.1;
let stepNumber = 1;

const redrawingAfter1Step = setInterval(() =>
for(let i = 0; i < currentData.length; i++)
currentData[i] = stepTick * stepNumber * finalData[i];


drawChart(currentData);

if ((stepNumber * stepTick) === 1)
clearInterval(redrawingAfter1Step);


stepNumber++;

, 500);






share|improve this answer










New contributor




Antoine Gautrain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer








edited 19 hours ago





















New contributor




Antoine Gautrain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered 20 hours ago









Antoine GautrainAntoine Gautrain

112




112




New contributor




Antoine Gautrain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Antoine Gautrain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Antoine Gautrain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Yes, that was my thought - but I don't know how to do that in the code

    – R.Dixon
    20 hours ago











  • I've added a JS Fiddle in the OP above. Try adding it there.

    – R.Dixon
    19 hours ago

















  • Yes, that was my thought - but I don't know how to do that in the code

    – R.Dixon
    20 hours ago











  • I've added a JS Fiddle in the OP above. Try adding it there.

    – R.Dixon
    19 hours ago
















Yes, that was my thought - but I don't know how to do that in the code

– R.Dixon
20 hours ago





Yes, that was my thought - but I don't know how to do that in the code

– R.Dixon
20 hours ago













I've added a JS Fiddle in the OP above. Try adding it there.

– R.Dixon
19 hours ago





I've added a JS Fiddle in the OP above. Try adding it there.

– R.Dixon
19 hours ago



















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55020228%2fcount-up-values-in-chart-js%23new-answer', 'question_page');

);

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







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко