-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Chartjs taking canvas width and height attribute, but ignoring css width height. #3378
Comments
@simonbrunel thoughts here? I think this is a duplicate of another issue |
For non responsive charts, some work has been done in #3356: style width and height are now used to initialize the canvas size if width and height attributes are not specified, so this should work: <canvas style="width: 512px; height: 256px"></canvas> BUT relative size does NOT work (e.g. |
For standard should work either, css Also should be very useful, if responsive:false; and not suport dynamic sizes such as width:100%;, let user to define size options like |
@gunins I totally agree with your second remark and I already started to rework the
What do you think? |
Sure when new Chart(ctx,{{
responsive: false,
width:500,
height:300,
scaleShowGridLines: false,
showScale: false,
maintainAspectRatio: this.maintainAspectRatio,
barShowStroke: false,
}}); P.S. This is kind of regards to different issue, but related to this one. |
What is your exact use case because I would not recommend to add these extra // From HTML
<canvas width="300" height="200"></canvas>
<canvas style="width: 300px; height: 200px"></canvas>
// Set size on chart creation
canvas.style.width = '300px'; // or canvas.width = 300;
canvas.style.height = '200px'; // or canvas.heigth = 200;
new Chart(canvas, { options: { responsive: false }});
// Change the display size
chart.resize(300, 200);
// Resync the render size
chart.resize(); /cc @chartjs/maintainers |
Reason for custom width and height is quite simple. Because Chartjs not support %, I can programmatically get with and height by pixels. But instead of DOM method |
Actually is there is any reason to take attribute width instead of |
<canvas style="width: 50%; height: 50vh"></canvas> I should have been more precise when I said "it doesn't work with relative sizes", because you can use css sizes in If your parent container size doesn't change, then it should already work as you expect :) |
Chartjs taking canvas width and height attribute, but ignoring css width height. Also there should be an option, where I can add width and height programmatically, true options.
The text was updated successfully, but these errors were encountered: