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

Add ability to lock aspect ratio of the grid, ignoring title and labels #11783

Open
mikethea1 opened this issue May 21, 2024 · 0 comments
Open

Comments

@mikethea1
Copy link

Feature Proposal

I am adding some charts to my website which will get viewed on various different devices and screen sizes.

Generally the default aspect ratio of 2:1 works great, but on smaller mobile screens like iPhone, the chart title, legend, and axis labels are larger relative to the grid and this warps the aspect ratio such that 2:1 creates a grid that is squashed horizontally.

I'm able to work around it by using an aspect ratio of 1.5, but I think it would be ideal if I could lock the ratio of the just the grid (since that's what defines the look/shape/readability of the graph itself) and then have the peripheral text fill in around that, potentially calculating a different final aspect ratio for the overall canvas.

Possible Implementation

From an API perspective, I could imagine surfacing this through a new option gridAspectRatio (or a better name) which is incompatible with aspectRatio. Alternatively, there could be an enum option which determines how aspectRatio is interpreted.

Internally, I imagine that Chart.js already knows how to calculate the size of the legend/title/labels and that this is taken into account when ultimately sizing the grid against the provided aspect ratio. If this is the case, then it should be possible to instead inform the canvas aspect ratio based on the grid's size + the peripherals.

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

1 participant