on-internet
← Community

Resize chart.js in Bootstrap grid layout while keeping aspect ratio

Stack Overflow ·

The chart.js chart in this Bootstrap 5 grid layout doesn't resize correctly: it shrinks when you drag the window narrower but doesn't re-grow when you drag it back. How can I fix this so that the chart fits the column width and keeps the desired aspect ratio? I'd prefer not to use any more libraries. new Chart( document.getElementById('canvas-id'), { type: 'bar', data: { labels: ['a', 'b', 'c'], datasets: [{ data: [3, 4, 2] }] }, options: { aspectRatio: 3.5, maintainAspectRatio: true } } ); <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" />

Comments

Sign in or sign up to comment and upvote.

No comments yet.