Bad*_*phs 3 javascript charts typescript zingchart angular
我有一个现有的项目,我想实现zingcharts.
我尝试了3个不同的教程,主要来自" https://blog.zingchart.com/2016/07/19/zingchart-and-angular-2-charts-back-at-it-again/ "博客.
但是我不能在我的项目中工作.因此,我决定首先尝试以最基本的方式实施它,然后尝试更好的方法.这就是我所做的,但它还没有购买.
作为angular2的新手,我不太确定这是否有用.
我去了ZingChart网站试图实现这个基本的例子 - > https://www.zingchart.com/docs/getting-started/your-first-chart/
所以我构建了2个文件chart.ts和chart.component.html并实现了
"<script src="https://cdn.zingchart.com/zingchart.min.js"></script>"
Run Code Online (Sandbox Code Playgroud)
在index.html中
//chart.ts
import { Component } from '@angular/core';
@Component({
selector: 'rt-chart',
templateUrl: './chart.component.html'
})
export class Chart
{
}
//chart.component.html
<!--Chart Placement[2]-->
<div id="chartDiv"></div>
<script>
var chartData = {
type: "bar", // Specify your chart type here.
title: {
text: "My First Chart" // Adds a title to your chart
},
legend: {}, // Creates an interactive legend
series: [ // Insert your series data here.
{ values: [35, 42, 67, 89]},
{ values: [28, 40, 39, 36]}
]
};
zingchart.render({ // Render Method[3]
id: "chartDiv",
data: chartData,
height: 400,
width: 600
});
</script>
Run Code Online (Sandbox Code Playgroud)
我在我已经在工作的网站上称它为
它没有显示出来.我究竟做错了什么?有什么我想念的东西.Angular2对我来说很新鲜.
谢谢
使用最新的angular2版本(@ 2.2.3),您可以利用这样的特殊ZingChart指令:
ZING,chart.directive.ts
declare var zingchart: any;
@Directive({
selector : 'zing-chart'
})
export class ZingChartDirective implements AfterViewInit, OnDestroy {
@Input()
chart : ZingChartModel;
@HostBinding('id')
get something() {
return this.chart.id;
}
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');
}
}
Run Code Online (Sandbox Code Playgroud)
哪里ZingChartModel只是图表的模型:
ZING,chart.model.ts
export class ZingChartModel {
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;
}
}
Run Code Online (Sandbox Code Playgroud)
这里完成了Plunker示例
| 归档时间: |
|
| 查看次数: |
964 次 |
| 最近记录: |