Chartjs-Why chartJs throws length of undefined although everything seems correct

0👍

Stackblitz demo: https://stackblitz.com/edit/line-chart-xmy3vt?file=app%2Fapp.component.html

You need an appropriate data format to pass to you chart canvas element based on the official example (array + object with data keyword)

 public lineChartData: ChartDataSets[] = [
    { data: [65, 59, 80, 81, 56, 55, 40]},
  ];

Changed html which gives the output

<div id="chart-container" *ngIf="charts">
    <ng-container *ngFor="let item of charts;let i=index">
        <canvas id="canvas" baseChart [chartType]="chartType" [datasets]="[dataSet[i]]" [labels]="item.yAxis">
        </canvas>
    </ng-container>
</div>

Leave a comment