amcharts3-angular2 icon indicating copy to clipboard operation
amcharts3-angular2 copied to clipboard

Question; Am I using Update correctly.

Open justinbleach opened this issue 7 years ago • 3 comments

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', {...

justinbleach avatar Dec 11 '17 20:12 justinbleach

@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.

Pauan avatar Dec 14 '17 10:12 Pauan

Any solution to this?

ravithb avatar Aug 28 '18 07:08 ravithb

My solution I posted here might help: #12

zuice32 avatar Nov 11 '18 07:11 zuice32