【发布时间】:2016-07-28 01:09:43
【问题描述】:
我想使用 angular2-highcharts 在 JSON 文件中绘制数据。
假设 JSON 文件中有以下格式的 X 和 Y 值:
[[[1,15],[2,16],[3,18]]]。代码如下。
@Component({
selector: 'my-app',
directives: [CHART_DIRECTIVES],
template:`{{sample}}
<center> <chart [options]="options"></chart></center>`
})
export class AppComponent {
public sample;
options:Object;
constructor(public http : Http) {
http.get('data.json')
.map(res => res.json())
.subscribe(data =>this.sample=JSON.parse(JSON.stringify(data || null)),
err=>console.log(err),
() => console.log('Completed')); {}
console.log(this.sample);
this.options = {
title : { text : 'Sample Curve' },
series: [
{ data: this.sample,
color:'red'},]
}
}
}
我在 .json 文件中获取数据值并将其显示为模板的一部分,并且似乎打印了正确的值。 但是,我的高图是空的。由于我对 Javascript 和打字稿同样陌生,因此我可能还没有充分利用这里的一些答案。
【问题讨论】:
标签: json highcharts typescript angular