[Chartjs]-How to send data to chart js using angular

1👍

Your component class looks fine to me. To make it work, you also need to define a canvas inside the HTML template.

<canvas id="myChart" height="200"></canvas>

The link between the canvas and the new Chart() in the component class is the id, which in your case is "myChart".

But I agree with the comment from AliF50. Using ng2-charts in an Angular application is a better choice.

0👍

I resolve the problem with this :

resultStorehora(op: any){
    this.horaxhoraService.postresultChart(op).subscribe(data=>{
      this.storeResult = data;
      this.resultadocharInit = data[0];
       this.salida = 0.0;
      this.salida = this.resultadocharInit['Resultado'];
      console.log(this.salida);
      
      this.chart.data.datasets[0].data = [this.salida.toFixed(2),400];
      this.chart.options.elements.center.text = this.salida.toFixed(2)+'%';

      this.chart.update();

    });
  }

Leave a comment