question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Responsive width sizing seems to be broken

See original GitHub issue

Describe 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:

  1. Using this version of ChartJSBlazor ‘1.1.0’.
  2. Run this code with Responsive = true and MaintainAspectRatio = false
  3. Resize window to a large size
  4. Resize window to a small size

Expected behavior

The chart resizes properly to fit its container

Screenshots

Capture

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
FlsZencommented, Feb 10, 2021

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:

<div style="position: relative; height:350px; width:80%; margin-left: auto; margin-right: auto;">
    <Chart Config="@_chart" />
</div>

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.

0reactions
Joelius300commented, Jan 24, 2021

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 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found