krispo / ng2-nvd3

Angular2 component for nvd3
http://krispo.github.io/ng2-nvd3/
MIT License
328 stars 104 forks source link

Chart doesnt update when data change #30

Closed codxse closed 8 years ago

codxse commented 8 years ago

Hallo, I am using nvd3 on ionic 2.0.0-beta.30. All working fine until I want update chart from onChange event.

Here my template:

<div>
  <nvd3 [options]="options" [data]="data"></nvd3>
</div>
<ion-list>
  <!-- <ion-item>
    <ion-label>Kategori</ion-label>
    <ion-select [(ngModel)]="kategori" (ngModelChange)="onChange($event, 'kategori')">
      <ion-option value="lowongan">Lowongan</ion-option>
      <ion-option value="pencari">Pencari</ion-option>
    </ion-select>
  </ion-item> -->
  <ion-item>
  <ion-label>Tahun</ion-label>
  <ion-select [(ngModel)]="tahun" (ngModelChange)="onChange($event, 'tahun')">
    <ion-option *ngFor="let data of dataArr" [ngValue]="data.tahun">{{data.tahun | date:'y'}}</ion-option>
  </ion-select>
</ion-item>
</ion-list>

and here my ng

  onChange(newValue, ngModel) {
    console.log("onChange");
    if (ngModel == 'tahun') {
      for (let element of this.dataArr) {
        if (element.tahun = newValue) {
          console.log(element.values);
          this.data = element.values;
          this.nvD3.updateWithData(this.data);
          break;
        }
      }
      this.dataArr.indexOf(this.dataArr.newValue);

      this.tahun = new Date(newValue);
      console.log(this.tahun);
    }
  }

Not that, I have tried this.nvD3.chart.update() too. Still not update the DOM. If you don't mind, here my full code https://github.com/codxse/batavia/blob/master/app/pages/ikhtisar-statistik-pie/ikhtisar-statistik-pie.ts

Thanks again Best Regards.

codxse commented 8 years ago

Sorry, my foolish mistake. this code (element.tahun = newValue) should be (element.tahun == newValue)