This is really my first time using Chart.js and I am importing it into an Angular component. I am trying to at this point just create a simple bar chart. I am getting the following error in my console:
core.controller.js:118 Failed to create chart: can't acquire context from the given item
not sure what I am doing wrong here!
this is the TS file for my component:
import { Component, OnInit } from '@angular/core';
import { Chart } from 'chart.js';
import { data } from './data';
@Component({
selector: 'app-propel-factor',
templateUrl: './propel-factor.component.html'
})
export class PropelFactorComponent implements OnInit {
chart = [];
labels: any = [];
data: any = [];
constructor() { }
ngOnInit() {
data.forEach(item => {
this.labels.push(item.name);
this.data.push(item.value);
});
this.chart = new Chart('canvas', {
type: 'bar',
labels: this.labels,
data: {
labels: this.labels,
data: this.data
},
options: {
responsive: true
}
});
}
}
and then my template is simply:
<div *ngIf="chart">
<canvas id="canvas">{{ chart }}</canvas>
</div>
I also wanted to go on record saying that i tried this fix chart.js Failed to create chart: can't acquire context from the given item and still go the same error!