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.

Chart in flex container overflows instead of shrinking when resized.

See original GitHub issue

Bug report

I have 2 codepen examples, one showing the expected behavior and the second showing the wrong behavior. I have a css grid layout where I’m including 2 charts inside 1 grid-template-column. The charts widths need to dynamically update to the column width which is 1 fr or 50%. When I have 1 chart it works as expected. When I have 2 charts the layout breaks.

Video Example: https://www.youtube.com/watch?v=654eoVkD8Rc

Codepen (working): https://codepen.io/oneezy/pen/RwrEgxr Codepen (not working): https://codepen.io/oneezy/pen/RwrEgvo

Explanation

What is the behavior you expect? I expect both charts to stay 100% width of parent container

What is happening instead? The brush charts dynamic width is not updating correctly thus breaking the layout

What error message are you getting? No error messages

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
junedchhipacommented, Jul 22, 2020

Adding overflow: hidden on the parent flex elements fixes this issue. https://stackoverflow.com/questions/52502837/chart-js-in-flex-element-overflows-instead-of-shrinking

So, in your case, add overflow: hidden to #ChartWrapper

2reactions
junedchhipacommented, Jul 21, 2020

Thanks for the detailed explanation. I can see the issue when using charts in Grid/FlexBox. It will be addressed soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chart.js in flex element overflows instead of shrinking
js, the chart had a fixed size, which caused the chart-container not to shrink (even when overflow: hidden was applied, I don't fully...
Read more >
flex-shrink - CSS: Cascading Style Sheets - MDN Web Docs
The flex-shrink CSS property sets the flex shrink factor of a flex item. If the size of all flex items is larger than...
Read more >
flex-shrink | CSS-Tricks
The flex-shrink property is a sub-property of the Flexible Box Layout module. It specifies the “flex shrink factor” which determines how ...
Read more >
CSS flex-shrink property - W3Schools
The flex-shrink property specifies how the item will shrink relative to the rest of the flexible items inside the same container.
Read more >
Flex Shrink - Tailwind CSS
Utilities for controlling how flex items shrink. ... Use shrink to allow a flex item to shrink if needed: 01. 02. 03. <div...
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