我有这样的数据:
var dataCharts = [{"value":54, "ru":"R201", "area":"HCC"}, {"value":4, "ru":"R401", "area":"HOC"}]
还有将数据推送到这样的变量的功能:
private datasetYearly: Array<any> = [{ data: [] }];
let res = [];
let dataSet = [];
res = Object.values(dataCharts.reduce((obj, curr) => {
if (!obj[curr.ru]) obj[curr.ru] = { ru: curr.ru, area: [] };
// push the current name into the current time entry
obj[curr.ru]['area'].push(curr.area);
return obj;
}, {}));
for (let a of res) {
// Get data value
for(let d of a.value){
dataSet.push(d);
}
// Console is 54, 4
}
this.datasetYearly.push({ data: dataSet });
然后绑定到模板:
<div style="display: block" class="selector">
<canvas baseChart width="40" height="40"
[datasets]="datasetYearly"
[labels]="labelYearly"
[options]="pieChartOptions"
[chartType]="pieChartType"></canvas>
</div>
但是我被压入dataChart变量中的数据也不会显示,只会显示空白字段。也许有人知道如何推销它。谢谢。