我在我的Angular 9应用程序中实现了Chart.JS。图表没有按预期呈现。
ngOnInit(): void {
this.smdashboardservice.fetchSmDashboardData().subscribe(response=>{
//let data = response.data
let data = [
{"label":"Application","sublabel":"Nice","count":2},
{"label":"Application","sublabel":"poor","count":1},
{"label":"Channels","sublabel":"Quality","count":2},
{"label":"Customer Care","sublabel":"support","count":2}
]
this.barChartLabels = Object.keys(data);
this.barChartLabels.forEach(label => {
this.barChartData[0].data.push(data[label]['count']);
});
})
}
字符串
当前代码给出图
的数据
但我期待着这样
1条答案
按热度按时间vnzz0bqm1#
您需要准备对
sublabel
进行分类的数据集。每个数据集应包含x轴类别长度(
label
)的值,即3。字符串
Demo @ StackBlitz
subLabelDatasets
可以简化为:型