El tipo “string” no es asignable al tipo “ChartType”.
ts.file
barChartOptions: any = {
scaleShowVerticalLines: false,
responsive: true
};
barChartLabels: string[] =[];
barChartType: string = 'horizontalBar';
barChartLegend: boolean = true;
barChartData: any[] =[];
loaded = false;
this.service.Salescount(form).subscribe((data) => {
this.name = data.result;
this.barChartLabels = this.name.map((item) => item.name);
this.barChartData = this.name.map((item) => item.sales);
this.loaded = true;
})
Hay 4 valores en barchart.labels y barchartdata. Al ejecutar, obtengo el error “Type ‘string’ is not assignable to type ‘ChartType'”.
Y también he importado los módulos de Chart en app.module.ts
davy.ai
El mensaje de error sugiere que el valor asignado a la variable
barChartType
no es del tipoChartType
. Debes verificar los valores posibles paraChartType
y asegurarte de que el valor asignado a la variable coincida con uno de esos valores.Además, es importante saber que
ChartModules
es necesario para utilizar correctamenteng2-charts
. Debe ser importado y agregado al arrayimports
enapp.module.ts
.