Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resposive chart infinitely shrinking with certain zoom levels #11612

Open
CamBurris opened this issue Dec 11, 2023 · 6 comments
Open

Resposive chart infinitely shrinking with certain zoom levels #11612

CamBurris opened this issue Dec 11, 2023 · 6 comments

Comments

@CamBurris
Copy link

CamBurris commented Dec 11, 2023

Expected behavior

Responsive chart should be a stable size with all devicePixelRatios.

Current behavior

Chart will infinitely shrink when certain devicePixelRatios are used.

Behavior occurs with a devicePixelRatio of 1.3499999046325684.

The ratio can be achieved naturally by users:

Windows 10
Screen resolution: 1920x1080
Windows resolution scaling: 150%
Chrome zoom level: 90%

Reproducible sample

https://codesandbox.io/p/sandbox/chartjs-responsive-zoom-thccwr

Optional extra steps/info to reproduce

Demo uses css zoom property. Need to use a browser that supports zoom, such as Chrome.

Possible solution

No response

Context

I believe this is the same issue as #10890.

Either the issue was reintroduced or the original fix didn't work for all scenarios.

chart.js version

4.4.1

Browser name and version

Chrome 119

Link to your project

No response

@PabloMartinez-Beemeral
Copy link

Same here with 3840x2160 screen, it happen in Edge, Chrome and Brave. But curiosly enough, not in Firefox. It will happen with both 90% and 110% zoom.

@abm0
Copy link

abm0 commented Mar 21, 2024

Encountered this issue with following versions:

    "chart.js": "4.4.1",
    "chartjs-plugin-annotation": "3.0.1",

@MernaAyman
Copy link

hello, I encountered this issue in chart.js v 4.4.3 also, is there any solution or workaround?

@HieroglypH
Copy link
Contributor

I also encountered this problem with Chart.js version 4.4.1.
In my case, the issue occurs only when the zoom level is set to 67%.

I managed to avoid this by setting the aspect-ratio on the wrapper element.
It seems that the problem may be related to handling non-integer pixel heights, which could cause continuous resizing.

@MernaAyman
Copy link

MernaAyman commented Aug 22, 2024

I also encountered this problem with Chart.js version 4.4.1. In my case, the issue occurs only when the zoom level is set to 67%.

I managed to avoid this by setting the aspect-ratio on the wrapper element. It seems that the problem may be related to handling non-integer pixel heights, which could cause continuous resizing.

Hello @HieroglypH, I already tried before to add aspect-ratio to the canvas but it doesn't work with both 90% and 125% zoom in chrome. I am using v4.4.3 to create doughnut chart.
Could you please share your fix in detail?

@HieroglypH
Copy link
Contributor

@MernaAyman

Sorry for the late reply.

I set the aspect-ratio not on the canvas, but on the wrapper element.

<div id="chart" class="wrapper">
  <canvas>
</div>
.wrapper {
  aspect-ratio: 1 / 2;
}

If that doesn't resolve the issue, how about setting the height on the wrapper element?

This phenomenon is caused by the canvas resizing itself repeatedly.
When the canvas size is determined by the wrapper element, the height of the canvas can become a non-integer pixel, triggering constant resizing.
Therefore, if the height of the wrapper element is independent of the canvas, it may stop the resizing loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants