Chartjs-Cant assign data to ng2 piechart after receiving it in HTTP response

0👍

I did some research on internet and read the documentation. I couldn’t find the definite answer for my problem. Following process worked for me:

  1. I downgraded chart.js from 2.4.0 to 2.3.0
  2. I added the boolean to my component to indicate data was received from RESTApi or not. I used that flag to display canvas using *ngIf.

HTML markup looks as follows:

<canvas 
            baseChart 
            class="chart"
            [data]="data.pieChartData"
            [labels]="data.pieChartLabels"
            [chartType]="data.pieChartType"
            (chartHover)="chartHovered($event)"
            (chartClick)="chartClicked($event)"
            *ngIf="isDataAvailable"
            >
    </canvas>

Leave a comment