Open justinbleach opened 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.
Any solution to this?
My solution I posted here might help: #12
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', {...