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

Is it possible to make charts a fixed height? #3384

Closed
lizbanach opened this issue Sep 28, 2016 · 8 comments
Closed

Is it possible to make charts a fixed height? #3384

lizbanach opened this issue Sep 28, 2016 · 8 comments

Comments

@lizbanach
Copy link

I have tried to change the height/width on the canvas element but it still seems to stretch to full browser width/height. Is there a way to make the canvas a fixed height but maintain the responsiveness of the charts? Thank you!

@panzarino
Copy link
Contributor

You can set max height on its container. Here is an example: http://codepen.io/pen?template=JXVYzq

@lizbanach
Copy link
Author

Thank you @zachpanz88 ! That worked great. Is there a way to let the width stretch to 100% while keeping a max-height on the element? It looks awkward for me to have a max-width and max-height on these charts. See screenshot below.

screen shot 2016-09-28 at 3 42 21 pm

@panzarino
Copy link
Contributor

You can remove the max-width. If you do not set a width and height on the canvas it will be responsive without a certain aspect ratio.

@panzarino
Copy link
Contributor

Closing as issue appears to be solved

@beausmith
Copy link

beausmith commented May 9, 2018

To get a fixed height and variable width chart…

  1. remove width or height attributes from the canvas element.
  2. set the desired css height on the canvas element's parent html element.
  3. set chart options to include maintainAspectRatio: false,

Here is a demo:
https://codepen.io/beau/pen/rvJRzb/

@alvinyen
Copy link

@beausmith thank you for saving my day!!

@jsina
Copy link

jsina commented Aug 7, 2018

I've done it with this code
<canvas style="width: 100% !important;height: auto !important;" id="canvas"></canvas>

@nicdnepr
Copy link

https://codepen.io/nicdnepr/pen/yLeOLdB
Who can help me with setting height to top chart directly?
I generate datasets from program and it can has more or less data
If I set big height in canvas and dataset is small, the chart is much bigger then legend
Or when small height in canvas and dataset is big, then it not display chart
I try to set height in canvas depends on dataset count, but can't find dependency

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

7 participants