Ng2-charts: is it pssible to set dynamic unequal width and height?

Created on 11 Jun 2019  路  1Comment  路  Source: valor-software/ng2-charts

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>

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_

@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>

>All comments

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>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

raychenfj picture raychenfj  路  3Comments

egervari picture egervari  路  4Comments

dslima90 picture dslima90  路  3Comments

Adwind picture Adwind  路  3Comments

RKornu picture RKornu  路  3Comments