Responsive width sizing seems to be broken
See original GitHub issueDescribe the bug
When resizing the window to be larger, then shrinking the window again, the canvas element maintains its largest size.
Which Blazor project type is your bug related to?
- Server-Side
Which charts does this bug apply to?
all charts
To Reproduce
Steps to reproduce the behavior:
- Using this version of ChartJSBlazor ‘1.1.0’.
- Run this code with Responsive = true and MaintainAspectRatio = false
- Resize window to a large size
- Resize window to a small size
Expected behavior
The chart resizes properly to fit its container
Screenshots
Code example
Please provide full code examples below where possible to make it easier for the developers to check your issues.
Please also add the working JavaScript equivalent so we can see what you were trying to achieve.
_config = new PieConfig
{
Options = new PieOptions
{
Title = new OptionsTitle
{
Display = true,
Text = "Sample chart from Blazor"
},
Animation = new ArcAnimation
{
AnimateRotate = true,
AnimateScale = true
},
Responsive = true,
MaintainAspectRatio = false
}
};
_config.Data.Labels.AddRange(new[] { "A", "B", "C", "D" });
var pieSet = new PieDataset
{
BackgroundColor = new[] { ColorUtil.RandomColorString(), ColorUtil.RandomColorString(), ColorUtil.RandomColorString(), ColorUtil.RandomColorString() },
BorderWidth = 0,
HoverBackgroundColor = ColorUtil.RandomColorString(),
HoverBorderColor = ColorUtil.RandomColorString(),
HoverBorderWidth = 1,
BorderColor = "#ffffff",
};
pieSet.Data.AddRange(new double[] { 4, 5, 6, 7 });
_config.Data.Datasets.Add(pieSet);
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
Why is my responsive layout broken? - css
Ok well it seems Firefox doesn't like calculating widths of elements when these elements don't have a width specified, which explains why ...
Read more >Responsive Header Problems - incorrect screen break
Hi Ashley,. It seems that the Bar 2 is still displayed none at the 995px screen size, but as the container width is...
Read more >Image is broken on bigger screen size how to make ...
Your Section has a fixed height of 500px on the largest breakpoint. This means the Section will always be 500px and ignore the...
Read more >broken img responsive size
The classes the AMP plugin is not able to determine the image size, width, and height, somehow it fails on that particular site....
Read more >Turning a Fixed-Size Object into a Responsive Element
If we wanted to make the devices half of their original size, we would need to divide every pixel measurement by 2. Before:...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I found myself in a similar situation where the chart wasn’t reacting to the narrowing of the window. Wrapping the chart in a
div
similar to what @swGLS mentioned, and similar to what Chart.js docs state, made it become responsive to the width narrowing. To get it to display nicely on my page, I wound up using a wrapper like this:I’m not sure if there’s some general solution that ChartJs.Blazor can provide. Chart.js seems to leave responsiveness up to the developer so this library may also have to pass the responsibility along as well.
This issue is still open because we couldn’t find the cause nor a (non-hacky) solution. But the pointer to the relative container might just be it. The fact that you managed to fix it with that is enough for me to close this now. If other people experience the same issue, they should comment below 😃