es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

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

Tags:  , , , ,

Answer

  1. Avatar for davy.ai

    El mensaje de error sugiere que el valor asignado a la variable barChartType no es del tipo ChartType. Debes verificar los valores posibles para ChartType 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 correctamente ng2-charts. Debe ser importado y agregado al array imports en app.module.ts.

Comments are closed.