]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
docs: Add note about flexbox/grid layout responsivity issue (#12134)
authorDrWarpMan 🌀 <36279265+DrWarpMan@users.noreply.github.com>
Mon, 20 Oct 2025 15:35:54 +0000 (17:35 +0200)
committerGitHub <noreply@github.com>
Mon, 20 Oct 2025 15:35:54 +0000 (17:35 +0200)
* 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 <oneinchwebbing@gmail.com>
docs/configuration/responsive.md

index ff2018f6f03b3fed914cfc59dd3568fc035cc02e..867dcde1459ced7ccbc36349678e45b58c9233b4 100644 (file)
@@ -41,6 +41,19 @@ chart.canvas.parentNode.style.width = '128px';
 
 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`.
 
+## Flexbox / Grid Layout
+
+To prevent overflow issues when using flexbox / grid layout, you must set the flex / grid child element to have a `min-width` of `0`.
+See [issue 4156](https://github.com/chartjs/Chart.js/issues/4156#issuecomment-295180128) for more details.
+
+```html
+<div class="grid-container" style="display: grid">
+  <div class="chart-container" style="min-width: 0">
+    <canvas id="chart"></canvas>
+  </div>
+</div>
+```
+
 ## Printing Resizable Charts
 
 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', () => {
 window.addEventListener('afterprint', () => {
   myChart.resize();
 });
-```
+```
\ No newline at end of file