Chartjs-Bind Angular FormGroup to Chartjs data

0👍

use this.formGenerator.valueChanges.subscribe(val => { ... });

Full code:

export class GeneratorComponent {

  public doughnutChartLabels = ['foo', 'bar'];
  public doughnutChartData;
  public doughnutChartType = 'doughnut';
  formGenerator: FormGroup;

  constructor(private formBuilder: FormBuilder) {
    this.doughnutChartData = [30, 15];
    this.formGenerator = this.formBuilder.group({
      sequenceNumberTime: 30,
      sequenceLetterTime: 15
    });
    this.formGenerator.valueChanges.subscribe(val => {
      this.doughnutChartData = [val.sequenceNumberTime, val.sequenceLetterTime];
    });
  }

}

Leave a comment