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

Size of chart isn't constrained by canvas element #3023

Closed
cfjedimaster opened this issue Jul 22, 2016 · 8 comments · Fixed by #3110
Closed

Size of chart isn't constrained by canvas element #3023

cfjedimaster opened this issue Jul 22, 2016 · 8 comments · Fixed by #3110

Comments

@cfjedimaster
Copy link

I'm using the default chart from the docs (http://www.chartjs.org/docs/#getting-started-creating-a-chart) and I've noticed that even though my canvas has a width and height of 400, the chart takes over the entire browser, it actually goes below the fold. I feel like something this wrong must be a dumb mistake on my part (grin), so what am I missing?

@Spone
Copy link

Spone commented Jul 22, 2016

Same problem here. The only solution I found is to constrain the width of the parent element.

@tiagoroldao
Copy link
Contributor

tiagoroldao commented Jul 22, 2016

You need to set responsive: false the Chart's options if you don't want it to resize to parent.

See here: http://www.chartjs.org/docs/#chart-configuration-common-chart-configuration

@cfjedimaster
Copy link
Author

According to the docs: Resizes when the canvas container does.

To me, that doesn't imply "I will get bigger than then canvas". Does it imply that to you? I could be reading it wrong.

@tiagoroldao
Copy link
Contributor

tiagoroldao commented Jul 22, 2016

It references the canvas container, not the canvas itself - meaning the parent. if your container (a div holding the canvas) constrains the canvas, then it'll only expand to that parent.

To be clear, the canvas is resized by Chart.js (if responsive: true), rather than Chart.js 'responding' to the canvas stretching.

@cfjedimaster
Copy link
Author

Ah - so if my canvas is 'naked' on the page, ie right under body.... ok. This makes sense.

Maybe the docs could make this is a bit clearer though - for slow folks like me? (And obviously I wasn't the only person to run into this.)

@tiagoroldao
Copy link
Contributor

tiagoroldao commented Jul 22, 2016

What do you mean? To make field description description clearer, or the behaviour and usage explanations more accessible?

For the former, the field description could be changed to Resizes the chart canvas when its container does.

For the latter, I don't know... Maybe adding a sample html file? This would need input from the project devs.

@cfjedimaster
Copy link
Author

Maybe the initial sample could include a div with a set size. I'd kind of imagine most people would not want a full screen chart. Not that it wouldn't make sense sometimes of course, but in general, I'd assume a set size.

@panzarino
Copy link
Contributor

Will add to my coming doc updates

exwm pushed a commit to exwm/Chart.js that referenced this issue Apr 30, 2021
Adds a lot of new information to the docs that will help developers better utilize the entire Chart.js library

List of implemented changes:
 - Reverse option for legends (resolves chartjs#3102)
 - Information about chart resizing (resolves chartjs#3023)
 - Mixed chart types (resolves chartjs#2825) (resolves chartjs#2431)
 - Chart library comparison table (resolves chartjs#2605)
 - getDetasetMeta function information (resolves chartjs#2521)
 - Popular Extensions (resolves chartjs#2365)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants