score:23
Try to set these options:
options: {
responsive: true,
maintainAspectRatio: false
}
If you set maintainAspectRatio to true, the height will be automatically calculated.
score:0
score:1
Use maintainAspectRatio
and responsive
options: {
responsive: true,
maintainAspectRatio: false,
}
let chart = new Chart('myChart', {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: true
}
}
}
});
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.6.2/dist/chart.min.js"></script>
<canvas id="myChart" width="400" height="400"></canvas>
score:6
Actually in Chart.js 3.2.1 to update the aspect ratio to add more height to your scheme you can use the aspectRatio
option:
options: {
aspectRatio: 1,
}
And so according to the documentation:
Canvas aspect ratio (i.e. width / height, a value of 1 representing a square canvas). Note that this option is ignored if the height is explicitly defined either as attribute or via the style.
You can set it such as:
1
for it to be square0.5
to be twice as high as wide2
to be twice as wide as high
Source: stackoverflow.com
Related Query
- Chart.js aspect ratio / forced height
- Chart.js change height on window resize while maintaining aspect ratio
- Chart.js: How to set minimum height of chart but still maintain aspect ratio?
- Set height of chart in Chart.js
- Chart.js: width and height of a pie chart not respected
- Fix the height of Y-Axis of Bar chart in chart.js?
- How to get the actual chart width and height in chart.js
- Changing width of chart.js chart without changing height
- React chart : prevent chart's canvas scaling with height and width
- Why would a ChartJS chart end up with width 0 and height 0?
- chart.js aspect ratio not square
- Css style not working well when resizing chart height in angular application
- Responsive Chart.js Doughnut Chart with minimum height
- ChartJS 2.6 - Bar chart fixed height scrollable-X
- How change chart height in chart.js
- Bar chart with min height and zero values - ChartJs
- Unable to set width and height on canvas in chart js
- Binding Chart to Canvas height width
- HorizontalBar chart is displayed below canvas when I set height with style attribute for chart div (Chart.js 2.9.4)
- Displaying a chartjs chart within a bulma full height hero
- Dynamically Setting Height of Chart
- what is wrong with my code ? java script chart position
- How to print a chart rendered by code
- chartjs - Not taking the height in reponsive chart
- Chart js legend are being cut off if the bar height is equal to port height - chart js
- attempting to change height and width of canvas for chart
- VueJS + Chartjs - Chart only renders after code change
- How do I destroy/update Chart Data in this chart.js code example?
- getting additional value fields from data source for dx.chartjs doughnut chart
- I am using chart js to draw a chart. I did everything right but i don't know why the x axis and y axis label is not comming in chart. code below
More Query from same tag
- How to reduce number of multiple gridlines in stack bar graph chart.js
- How to use an npm package (chart.js) once installed?
- How to customize chart using chartJs?
- Chart JS, backgroundColor not showing
- Trouble getting Axis Labels to show up in Chart.js
- How to use dates as X axis with Chart.js even when there is no Y axis value related
- Stacked horizontal bar chart along total count with chart.js
- how to filter dataset from labels using ChartJS
- Php Array to line chart in ChartJs
- How to Save as png with ChartJSRadar in R?
- ChartJS 'Hello World' not animating
- How to set global/specific properies when updating line-chart using Chart.js?
- Use Google Spreadsheet as data source for Chart.js
- how to change scales title position in chart.js
- Implementing ChartJs
- chart.js v 2.0.1 line, scatter chart pointRadius bug or I'm doing it wrong
- How to display label inside pie chart in Chartkick?
- Display data label (legend) in line-chart using chartjs
- How can I tighten letter spacing on labels with ChartJS?
- chart cannot read multiple datasets from the back-end (single data is fine)
- how to remove odd number from yaxes in chartjs using angular?
- Creating a Reusable Chartjs Function
- Add different labels in a line chart - Chart.js
- Doughnut chart from Chart.js, custom legend and call of original handler not works as expected
- Chartjs charts drawing with the same colour after update
- Chart.js get array of currently visible points on graph
- Want to save chart.js charts to image using django cron job
- How to remove square label from tooltip and make its information in one line?
- Chartjs doughnut chart rounded corners for half doghnut
- Chartjs display multiple info with different units in label