【发布时间】:2018-02-16 15:44:38
【问题描述】:
我想在有角度的材料选项卡中显示图表。但是选项卡初始化似乎是异步的,因此 c3js 找不到 div #detailed-chart 并且我的选项卡仍然为空。
模板
<mat-card class="col-xs-12">
<mat-card-title>
Detailed Utilization
</mat-card-title>
<mat-tab-group>
<mat-tab label="Chart">
<div id="detailed-chart" style="height: 200px"></div>
</mat-tab>
<mat-tab label="Table">
</mat-tab>
</mat-tab-group>
</mat-card>
组件
export class UtilizationComponent implements OnInit {
ngOnInit() {
this.detailedChart = c3.generate({
bindto: '#detailed-chart',
data: {
x: 'date',
columns: [
['date'],
['room'],
['desk'],
['office']
]
},
axis: {
x: {
type: 'timeseries',
tick: {
format: '%m.%Y'
}
},
y: {
tick: {
format: d3.format('.1%')
}
}
}
});
}
}
我也试过手动找div,好像不存在。
const x = window.document.getElementById('detailed-chart');
console.log('foo', x);
输出
foo 为空
问题
在这里加载动态元素的 angluarish 方式是什么?我是否需要为此选项卡创建单独的组件?
【问题讨论】:
标签: angular typescript tabs angular-material c3.js