I am relatively new to web applications and hence am just beginning to use Angular2 (have NOT used angularJS) and Typescript. I am trying to use Zingchart to plot a graph. I went through the 5 min quick start as well as the tutorial in the angular2 page and got a decent idea of how it works. I followed the instructions on the Zingchart page to create a chart on the webpage using the two tools (https://blog.zingchart.com/2016/03/16/angular-2-example-zingchart/). However, I seem to be having issues. 1) I am not able to import AfterView from @angular/core. Although the page says that I must be using angular2/core I am using @angular/core as the source folder to import modules from. angular2/core is not getting recognized. 2) When there are functions bound to the zingchart object (example - zingchart.render(), zingchart.exec()), there is an error that says zingchart cannot be found. I am not sure what is going on wrong here either.
import { Component, NgZone, AfterViewInit, OnDestroy } from '@angular/core';
class Chart {
id: String;
data: Object;
height: any;
width: any;
constructor(config: Object) {
this.id = config['id'];
this.data = config['data'];
this.height = config['height'] || 300;
this.width = config['width'] || 600;
}
}
@Component({
selector : 'zingchart',
inputs : ['chart'],
template : `
<div id='{{chart.id}}'></div>
`
})
class ZingChart implements AfterViewInit, OnDestroy {
chart : Chart;
constructor(private zone:NgZone) {
}
ngAfterViewInit() {
this.zone.runOutsideAngular(() => {
zingchart.render({
id : this.chart['id'],
data : this.chart['data'],
width : this.chart['width'],
height: this.chart['height']
});
});
}
ngOnDestroy() {
zingchart.exec(this.chart['id'], 'destroy');
}
}
//Root Component
@Component({
selector: 'my-app',
directives: [ZingChart],
template: `
<zingchart *ngFor="#chartObj of charts" [chart]='chartObj'></zingchart>
`,
})
export class App {
charts : Chart[];
constructor() {
this.charts = [{
id : 'chart-1',
data : {
type : 'line',
series : [{
values :[2,3,4,5,3,3,2]
}],
},
height : 400,
width : 600
}]
}
}