i'm trying to set dynamic unequal width and height for the canvas without success (example: width=900px and height="600px)
this is my code:
<div class="flex" [ngStyle]="{'width': width,'height': height}"><div class="flex-item"><div tyle="display: block;"> <canvas baseChart width="100%" height="100%" [datasets]="lineChartData" [labels]="lineChartLabels" [options]="lineChartOptions" [colors]="lineChartColors" [legend]="lineChartLegend" [chartType]="chartType" [plugins]="lineChartPlugins" (chartHover)="chartHovered($event)" (chartClick)="chartClicked($event)"></canvas>
</div>
</div>
</div>
I solved that with this code. If you wanna resize graph you must resize _.chart-container_. I hope that help you.
_graph.component.scss_
@import "../../../../../../node_modules/bootstrap/scss/functions";
@import "../../../../../../node_modules/bootstrap/scss/variables";
@import "../../../../../../node_modules/bootstrap/scss/mixins";
.chart-container {
@include media-breakpoint-up(sm) {
height: 40vh !important;
}
@include media-breakpoint-down(sm) {
height: 20vh !important;
}
}
canvas {
height: 100% !important;
width: 100% !important;
}
_graph.component.ts_
....
responsive: true,
maintainAspectRatio: false,
...
_graph.component.html_
<div class="col-12 chart-container">
<canvas baseChart
[datasets]="lineChartData"
[labels]="lineChartLabels"
[options]="lineChartOptions"
[colors]="lineChartColors"
[legend]="lineChartLegend"
[chartType]="lineChartType"></canvas>
</div>
Most helpful comment
I solved that with this code. If you wanna resize graph you must resize _.chart-container_. I hope that help you.
_graph.component.scss_
_graph.component.ts_
_graph.component.html_