chartjs / chartjs/Chart.js

Animation doesn't work if I change the size of pie chart

Open
#12,167 1 comment 0 reactions 0 assignees View on GitHub
type: documentation
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### Documentation Is:

- [x] Missing or needed?
- [x] Confusing
- [ ] Not sure?

### Please Explain in Detail...

When I change the size of my chart animation and reload the page, the animation sometimes doesn’t work. I tested different sizes and found that it only works reliably when the size is a multiple of 4. After hours of investigation, I realized this happens because my devicePixelRatio (DPR) is 1.25.

With a fractional DPR, Chart.js calculates the chart radius as a non-integer. When the canvas tries to draw the animation, the browser rounds the size, which triggers a resize internally. As a result, the animation does not play.

I think this behavior should be mentioned in the Chart.js documentation, as it can be confusing for developers.

### Your Proposal for Changes

Write about this behaviour in documentation

### Example

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.