diff --git a/website/astro.config.js b/website/astro.config.js index 1a5ff23ab..d7f2f0d08 100644 --- a/website/astro.config.js +++ b/website/astro.config.js @@ -183,6 +183,7 @@ export default defineConfig({ 'faq/maintain-aspect-ratio', 'faq/chartjs-instance', 'faq/canvas-context', + 'faq/plugins', 'faq/why-two', 'faq/fill-property', 'faq/registered-element', diff --git a/website/src/content/docs/faq/index.md b/website/src/content/docs/faq/index.md index dbb4685cf..7128e5603 100644 --- a/website/src/content/docs/faq/index.md +++ b/website/src/content/docs/faq/index.md @@ -9,6 +9,7 @@ Answers to the questions that come up most often. - [Why doesn't the chart maintain its width/height?](/faq/maintain-aspect-ratio/) - [How to access the Chart.js instance?](/faq/chartjs-instance/) - [How to access the canvas context?](/faq/canvas-context/) +- [Why doesn't the chart use new plugins?](/faq/plugins/) - [Why does react-chartjs-2 have "2" in its name?](/faq/why-two/) - [Why is a background fill not working?](/faq/fill-property/) - [How to fix "... is not a registered element" error?](/faq/registered-element/) diff --git a/website/src/content/docs/faq/maintain-aspect-ratio.md b/website/src/content/docs/faq/maintain-aspect-ratio.md index 18b91d05e..8500339df 100644 --- a/website/src/content/docs/faq/maintain-aspect-ratio.md +++ b/website/src/content/docs/faq/maintain-aspect-ratio.md @@ -1,16 +1,33 @@ --- title: "Why doesn't the chart maintain its width/height?" -description: "Make a react-chartjs-2 chart keep a custom width and height by setting the maintainAspectRatio option to false." +description: "Size a react-chartjs-2 chart with a container of its own and maintainAspectRatio set to false, or give it a fixed size with responsive set to false." prev: FAQ --- -In order for Chart.js to obey the custom size you need to set `maintainAspectRatio` to `false`: +A chart is responsive by default: Chart.js takes its size from the parent element and keeps the aspect ratio, so the `width` and `height` props only set the size the canvas starts with. + +To give the chart a size of your own, set `maintainAspectRatio` to `false` and put the chart in a container of its own, with `position: relative` and the size you need: + +```tsx +