amcharts / amcharts3-angular2

Official Angular 2 plugin for amCharts V3
99 stars 35 forks source link

Question; Am I using Update correctly. #64

Open justinbleach opened 6 years ago

justinbleach commented 6 years ago

I'm getting: Cannot set property 'innerHTML' of null - which I believe is because AmChart can't find my div. However I am using ngAfterViewInit like so (I have imported AfterViewInit and used it '...implements AfterViewInit, OnInit'):

ngOnInit() { this.managerService.getDeviceStatus().subscribe(data => {this.deviceStatus = data}); }

ngAfterViewInit() { this.chart = this.createDefaultChart(); this.populateInitialData() } poplateInitialData() { var deviceDataset:any = new Object(); deviceDataset.title = currDatasetTitle; deviceDataset.categoryField = 'timestamp'; deviceDataset.fieldMappings = []; deviceDataset.dataProvider = this.deviceStatus; this.AmCharts.updateChart(this.chart, () => this.chart.dataSets.push(deviceDataset)}); }

<div id="chartDiv" [style.height.px]="chartDivHeight"></div>

And my chart creation is: createDefaultChart(): AmChart { var defaultChart:AmChart = this.AmCharts.makeChart('chartDiv', {...

Pauan commented 6 years ago

@justinbleach Try moving the dataSets object inside the createDefaultChart method, and then change populateInitialData like this:

poplateInitialData() {
  this.AmCharts.updateChart(this.chart, () => {
    this.chart.dataSets[0].title = currDatasetTitle;
    this.chart.dataSets[0].dataProvider = this.deviceStatus;
  });
}

Also, make sure that you are setting fieldMappings properly, it is mandatory for stock charts.

If that doesn't work, please give me your full code so I can figure out what the problem is.

ravithb commented 6 years ago

Any solution to this?

zuice32 commented 6 years ago

My solution I posted here might help: #12