score:0
In case anyone comes across this question in the future (like I did), there is a new way of changing the animation duration. I guess this was an update to the Chart.js library at some point :-)
Chart.defaults.global.animation.duration = [ms];
So, for example, if you want a very fast 200ms animation, you can:
Chart.defaults.global.animation.duration = 200;
Hope this helps someone :-)
score:4
Use the animation object
options: {
animation: {
duration: 2000,
},
I haven't see this documented anywhere, but it's incredibly helpful to not have to set the speed globally for every chart.
score:7
I love Chart.js, but this is definitely a part of the API that could stand to be improved for the sake of clarity.
Chart.js uses the window.requestAnimationFrame() method for animations, which is a more modern and efficient way to animate in the browser, since it only redraws on each screen refresh (i.e., based on the screen refresh rate, usually 60Hz). That prevents a lot of unnecessary calculations for frames that will never actually render.
At 60 frames/second, one frame lasts 16-2/3 milliseconds (1000ms / 60). Chart.js appears to round this off to 17ms, though. The API allows you to specify the number of steps globally, e.g.:
Chart.defaults.global.animationSteps = 60;
new Chart(ctx).Doughnut(data, {
animationSteps: 60
});
Multiply 60 steps by 17ms/frame and your animation will run 1020ms, or just over one second. Since JavaScript programmers are used to thinking in milliseconds (not frames at 60Hz), to convert the other way, just divide by 17 to get the number of steps, e.g.:
Chart.defaults.global.animationSteps = Math.round(5000 / 17); // results in 294 steps for a 5-second animation
Hope that helps. I'm not sure what would cause those weird artifacts, though.
Source: stackoverflow.com
Related Query
- Chart.js - How to set a line chart dataset as disabled on load
- chart js 2 how to set bar width
- How set color family to pie chart in chart.js
- chartjs : how to set custom scale in bar chart
- Set Animation speed - ChartJS?
- Chart.js - How to set animation speed?
- how to set chart.js grid color for line chart
- How do you set pie chart colors in angular-chart.js
- How to dynamically set ChartJs line chart width based on dataset size?
- How to set single color on each bar in angular chart js
- How to make bar chart animation where all bars grow at the same speed?
- Chart.js - How to show loading animation before plotting chart
- ng2-charts: How to set Title of chart dynamically in typescript
- How do I set a bar chart to default to a suggested maximum in chart.js v1.01?
- How to use set the color for each bar in a bar chart using chartjs?
- How to set the xAxes min and max values of time cartesian chart in Chart.js
- How to set custom Y Axis Values (Chart.js v2.8.0) in Chart Bar JS
- How to set a time scale to a ChartJS chart from JSON?
- How to set X coordinate for each bar with react chart js 2?
- How to set the gap between data items in a chartjs chart
- How to set minimum value to Radar Chart in chart js
- How do you set x and y axis and Title for a line chart using charts.js?
- How to set 3 axis in google chart (V-Axis Left as Qty, V-Axis Right as Series Column and H-Axis as TimeOrder)?
- How do you set up a chart.js scatter line chart through angular-chart.js?
- How to show/hide animation when legend clicked chart js
- How to print a chart rendered by code
- How to set up a simple pie chart using React in ChartJS on codesandbox
- react-chartjs-2 how to set multiple background levels within a line chart
- How to set the number of of rows in a line chart in chart.js?
- How to set Solid label in bar chart using Chart JS
More Query from same tag
- MYSQL Query and Chart.js and PHP
- Chart Js - Globally set bar chart color based on value
- Different labels needed for second line graph, chart js
- Chartjs with Vue, Bar Chart Border Radius not working
- Show multiple data in a single data in chart.js
- Chart.js PolarArea not able to chance arc width and color
- chart.js scatter chart - displaying label specific to point in tooltip
- Charts.js in Angular 7 - working with imported time for timeseries
- ng-chart.js - First data set always has color gray
- Chart.js - combine data and label into a single object
- How can I debug maxTicksLimits in charts.js?
- Chartjs small offset on top
- Chartjs with Node.js : Unexpected token <
- How do I add an image in the middle of Donut Chart?(Chart.js)
- X-axis multiple colored label for bar chart using chart.js
- How to set global/specific properies when updating line-chart using Chart.js?
- Laravel - How to Display both count and percentage (%) in chartjs pie chart
- My Chart.js Options referencing React state are being ignored
- Chart js sum of grouped bars
- How to embed chart.js in angular-seed
- Hide chart labels
- Chart.js bubble chart pointStyle not working
- chartjs: How to create single outer border for stacked barchart
- Vue-Chartjs reactive chart options passing
- Chart.js multiTooltip labels
- Ionic/Chart.js - Cannot read property 'nativeElement' of undefined
- Chartjs doughnut chart with gradient color
- ChartJS BoxWidth not working
- Chart.js, returning an "date" array to plot the line graph
- ng2-charts access chartjs object to apply chartjs functions