score:126
You can override the canvas style width !important ...
canvas{
width:1000px !important;
height:600px !important;
}
also
specify responsive:true,
property under options..
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
update under options added : maintainAspectRatio: false,
score:-3
Use this, it works fine.
<canvas id="totalschart" style="height:400px;width: content-box;"></canvas>
and under options
,
responsive:true,
score:-2
You can create a div to wrap the canvas tag,
<div class="wrap">
<canvas id="myChart"></canvas>
</div>
.grafico{
width: 400px !important;
}
any changes in js chart options
var myChart = new Chart(ctx, {
type: 'bar', //doughnut, bar, line, radar, pie, polarArea
data: data,
options: {
scales: {
y: {
beginAtZero: true,
stepSize: 1
}
}
},
});
};
score:0
Not mentioned above but using max-width
or max-height
on the canvas element is also a possibility.
score:0
The below worked for me - but dont forget to put this in the "options" param.
var myChart = new Chart(ctx, {
type: 'line',
data: data,
options: {
maintainAspectRatio: false,
responsive:true,
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
score:1
This helped in my case:
options: {
responsive: true,
scales: {
yAxes: [{
display: true,
ticks: {
min:0,
max:100
}
}]
}
}
score:4
You can change the aspectRatio
according to your needs:
options:{
aspectRatio:4 //(width/height)
}
score:14
I cannot believe nobody talked about using a relative parent element.
Code:
<div class="chart-container" style="position: relative; height:40vh; width:80vw">
<canvas id="chart"></canvas>
</div>
Sources: Official documentation
score:32
In my case, passing responsive: false
under options solved the problem. I'm not sure why everybody is telling you to do the opposite, especially since true is the default.
score:86
You can also simply surround the chart with container (according to official doc http://www.chartjs.org/docs/latest/general/responsive.html#important-note)
<div class="chart-container">
<canvas id="myCanvas"></canvas>
</div>
CSS
.chart-container {
width: 1000px;
height:600px
}
and with options
responsive:true
maintainAspectRatio: false
Source: stackoverflow.com
Related Query
- Setting width and height
- Changing width and height in angular-chart.js module
- Resize the width and height of the ng2-charts
- Chart.js: width and height of a pie chart not respected
- How to get the actual chart width and height in chart.js
- Width and Height in Chart.js
- React chart : prevent chart's canvas scaling with height and width
- Why would a ChartJS chart end up with width 0 and height 0?
- Keep chart.js doughnut with fixed width and height centered in container
- canvas does not display proper width and height chart.js
- I can not properly re scale <canvas> with width and height attributes
- Unable to set width and height on canvas in chart js
- How to set responsive width and height of canvas?
- Customise size of data points , height and width in Chart.js?
- Html canvas element resets width and height to zero after drag/drop
- attempting to change height and width of canvas for chart
- How to shrink the height and increase the line width of a custom Chartjs horizontal line?
- Prevent size of canvas chart js to equal window height and width
- Chart.js ignoring canvas height & width
- How to use PrimeNg Chart of Width and Height?
- Chart.js - Setting max Y axis value and keeping steps correct
- Changing width of chart.js chart without changing height
- How to select and pass array object to data setting of chart.js config?
- Setting Common labels and background color common for all the charts in ChartJs
- Setting up min and max in chartjs did not work
- How to style a pie chart in chart js? I want to change the border color, border width and give them shadow
- Bar chart with min height and zero values - ChartJs
- Setting max, min and stepSize values in a Chart.js graph
- Chart.js canvas and chart width gets overwritten when redrawn
- Setting min and max values chart.js
More Query from same tag
- Non numeric for x-axis in scatter chart in CHART.js
- Chart.js: How can I set paddings and draw a background box in a line chart?
- react-chartjs-2 fill property not working?
- how to make a chart.js bar chart scrollable
- How can i launch a modal after clicking each bar in Bar chart in Chartjs and also how can i get its data?
- Fill color to pointer in Chartjs
- multiple horizontal bar charts to display in same row
- Angular-Chart.js - Tooltip not working with 0 values
- How to apply data dynamically on initialisation for chart.js in angular?
- vue-chartjs v4 reference to the chart object
- charts.js from session var, flicker effect
- Dotted Line in ChartJS
- Label Color same as backgroundColor - ChartJS
- Chart.js separation lines
- Different color for each bar in a bar chart; ChartJS
- Chart.js Update to X Axis Not Updating
- angular-chart chart-line not working
- Chart.js Label Issue
- Horizontal floating bars with a time y-axis in Chart.js
- How do I implement the 'autoskip' feature in chartjs?
- how to show chart using chart js
- Send data from php to chart with ajax
- Using chart.js to output chart as a saved image rather than using canvas
- Chart.js x-axis label duplicating on hover
- Show Dates in x-axis when using chart.js
- Stacked bar chart with chartjs with included values
- ChartJS row size
- Count all distinct values from JSON in javascript for ChartJS
- How can I set the yAxis scale for the chart?
- How to add text in centre of the doughnut chart using Chart.js?