Skip to content

Commit 2bbb96c

Browse files
docs: Add note about flexbox/grid layout responsivity issue (#12134)
* note added to docs for proper responsive sizing when the chart parent element is a child of a flex or grid container * revert style changes * improve docs * dev --------- Co-authored-by: DavidAshburn <[email protected]>
1 parent 67f67ae commit 2bbb96c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

docs/configuration/responsive.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ chart.canvas.parentNode.style.width = '128px';
4141

4242
Note that in order for the above code to correctly resize the chart height, the [`maintainAspectRatio`](#configuration-options) option must also be set to `false`.
4343

44+
## Flexbox / Grid Layout
45+
46+
To prevent overflow issues when using flexbox / grid layout, you must set the flex / grid child element to have a `min-width` of `0`.
47+
See [issue 4156](https://github.com/chartjs/Chart.js/issues/4156#issuecomment-295180128) for more details.
48+
49+
```html
50+
<div class="grid-container" style="display: grid">
51+
<div class="chart-container" style="min-width: 0">
52+
<canvas id="chart"></canvas>
53+
</div>
54+
</div>
55+
```
56+
4457
## Printing Resizable Charts
4558

4659
CSS media queries allow changing styles when printing a page. The CSS applied from these media queries may cause charts to need to resize. However, the resize won't happen automatically. To support resizing charts when printing, you need to hook the [onbeforeprint](https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeprint) event and manually trigger resizing of each chart.
@@ -62,4 +75,4 @@ window.addEventListener('beforeprint', () => {
6275
window.addEventListener('afterprint', () => {
6376
myChart.resize();
6477
});
65-
```
78+
```

0 commit comments

Comments
 (0)