[英]Not able to convert data to ng2-chart [ Bar Chart ]
我是angular的新手,正在使用Angular 7,我需要將我的api數據轉換為ng2-charts格式。
以下是我的api數據:
{
"status": 200,
"message": "Fetched Successfully",
"data": [
{
"1": [
{
"productid": "5c595f1c736429312f1ee15b",
"totalQty": 5
},
{
"productid": "5c595f1c736429312f1ee158",
"totalQty": 54
},
{
"productid": "5c595f1c736429312f1ee157",
"totalQty": 156
}
],
"2": [
{
"productid": "5c595e3b736429312f1ee155",
"totalQty": 15
},
{
"productid": "5c595f1c736429312f1ee157",
"totalQty": 42
}
],
"5": [
{
"productid": "5c595e3b736429312f1ee155",
"totalQty": 50
},
{
"productid": "5c595f1c736429312f1ee157",
"totalQty": 70
}
],
"12": [
{
"productid": "5c595e3b736429312f1ee145",
"totalQty": 17
},
{
"productid": "5c595f1c736429312f1ee157",
"totalQty": 5
}
]
}
]
}
以下是我預期的輸出格式:
public barChartLabels = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']; // all months
public barChartType = 'bar';
public barChartLegend = true;
public barChartData = [
{ data: [5], label: '5c595f1c736429312f1ee15b' },
{ data: [54], label: '5c595f1c736429312f1ee158' },
{ data: [156, 42, , , 70, , , , , , , 5], label: '5c595f1c736429312f1ee157' },
{ data: [, 15, , , 50], label: '5c595e3b736429312f1ee155' },
{ data: [, , , , , , , , , , , 17], label: '5c595e3b736429312f1ee145' },
{ data: [, 15], label: '5c595e3b736429312f1ee145' }
];
我想使圖表具有動態性,因為API會提供動態數據。
我已經嘗試過使用循環,但是它增加了復雜性,並且花費時間,因此尋找有效的解決方案。
提前致謝
您好,希望此幫助:“ https://github.com/valor-software/ng2-charts/issues/662 ”該問題已在上面的鏈接中關閉。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.