score:16
Accepted answer
the documentation for chartjs states that you need to set maintainaspectratio
to false for it to use the width and height props that you pass into your chart.
in order for chart.js to obey the custom size you need to set
maintainaspectratio
to false.
<doughnut
data={data}
width={"30%"}
options={{ maintainaspectratio: false }}
/>
score:0
doing the following works for me:
- set height and width on the
<doughnut />
component. - set the maintainaspectration to false.
here is what the outcome looks like:
<doughnut
data={data}
height="200px"
width="200px"
options={{ maintainaspectratio: false }}
/>
score:2
wrap it in div
container and set width and height.
ex:
<div style={{height:"60vh",position:"relative", marginbottom:"1%", padding:"1%"}}>
<doughnut options={options} data={chartdata} />
</div>
Source: stackoverflow.com
Related Query
- How to clear/destroy Chart.js canvas when the chart is represented as a react JSX element
- How to resize Chart.JS element in React.js?
- how to get React chartjs to resize back down with window
- ChartJS - how to display line chart with single element as a line? (not as a dot)
- Cannot create chart on react element
- How to set X coordinate for each bar with react chart js 2?
- React & Chartjs: How can I best destroy my chart when re-rendering?
- How to print a chart rendered by code
- How to add variable-pie chart to react project?
- How to set up a simple pie chart using React in ChartJS on codesandbox
- How do I destroy/update Chart Data in this chart.js code example?
- How to add faded background to stack chart in react native
- How to change React line chart tooltip title font family in chart.js
- How to save in chart original ID of element in array that is used to build chart data labels?
- How to run Chart.js samples using source code
- How to populate entire box inside a React chart (between two axes)
- how to not repeat code while creating multiple charts in chart js
- How to use the useEffect function in react js chart 2 to change the labels?
- How to access custom property in dataset object in Bar Chart in React ChartJS 2?
- How to add text inside the doughnut chart using Chart.js?
- How to clear a chart from a canvas so that hover events cannot be triggered?
- Chart.js - How to set a line chart dataset as disabled on load
- chart js 2 how to set bar width
- How can labels/legends be added for all chart types in chart.js (chartjs.org)?
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- How can I make two of my lines in Chart JS thicker
- How to prevent first/last bars from being cut off in a chart with time scale
- How set color family to pie chart in chart.js
- Chart.js Bar Chart - how to chart bars from 0
- How to add an on click event to my Line chart using Chart.js
More Query from same tag
- Line chart disable interpolation
- ChartJs title not showing
- Array is not being updated in useState hook?
- Chart.js: Bar chart multiple colors
- Chart.JS Global Options
- Pie Charts JS: How to set units?
- How Export an Editable Chart with content to PPT and Excel
- How to draw round edges with chart.js for line diagrams
- How to take data from an API and create a chart on that using Chart.js and Angular 8?
- ChartJS replay chart animation when called by show()
- chartjs chart.update() function not rendering lines in foreground
- Count up values in Chart JS
- How to set 2 y-axis title (and/or label) on chartjs?
- How to highlight a section of a stack in all bars in a stacked barchart in chartjs
- How to give break line in data label
- Chart.js V2 ticklines no grid
- React js with react-chart js, does not render doughnut chart
- Displaying labels on a Doughnut Chart using Chart.js
- HTML in Chart.js labels
- How to show data values in top of bar chart and line chart in chart.js 3
- chartjs with local dates
- Destroy chart.js bar graph to redraw other graph
- How to put static pointDots and make vertical line in Chart.js
- Is there any way to get Chiselled Effect in chart js?
- Can I use a variable as index in for loop in python?
- How to show text likt this in Chartjs Dougnet chart
- Add new line in es6 inside a doughnut chart
- Modifying values in a radar chart.js based on user input
- Click anchors the label to its respective section HTML in Chart.js
- Problems hovering over ChartJS bar chart after being redrawn