【发布时间】:2021-10-31 06:40:30
【问题描述】:
我有以下数据:
const rawData=[
{
Order_Date: "2020-08-11",
Region: "South",
Product_Name: "Bookcase",
Sales: 261.96
},
{
Order_Date: "2020-08-13",
Region: "South",
Product_Name: "Stacking Chairs",
Sales: 731.94
},
{
Order_Date: "2020-08-11",
Region: "Central",
Product_Name: "Table",
Sales: 200
},
{
Order_Date: "2020-08-11",
Region: "East",
Product_Name: "Chairs",
Sales: 350
},
{
Order_Date: "2020-10-06",
Region: "South",
Product_Name: "Stacking Chairs",
Sales: 700.45
},
{
Order_Date: "2020-10-06",
Region: "Central",
Product_Name: "Chairs",
Sales: 500
},
{
Order_Date: "2020-12-06",
Region: "East",
Product_Name: "Self-Adhesive Address Labels for Typewriters by Universal",
Sales: 14.62
},
{
Order_Date: "2019-11-15",
Region: "East",
Product_Name: "Table",
Sales: 957
},
{
Order_Date: "2019-11-10",
Region: "East",
Product_Name: "Eldon Fold",
Sales: 22
}
]
预期输出:
[
{
Order_Date: "2020-08",
East: 350,
South: 993.90,
Central: 200
},
{
Order_Date: "2020-10",
East: 0,
South: 700.45,
Central: 500
},
{
Order_Date: "2019-11",
East: 989,
South: 0,
Central: 0
},
{
Order_Date: "2020-12",
East: 14.62,
South: 0,
Central: 0
},
]
我想按年和月 ("YYYY-MM") 对所有 Order_Date 进行分组,并为每个 Order_Date ("YYYY-MM") 组放置每个 Region 值的销售额总和。
我需要像Nivo Bar Chart 数据一样转换数据。但我找不到任何关于转换数据的 nivo 文档。
【问题讨论】:
-
同一个
Order_Date有多个区域时输出应该如何? -
是的,我已经更新了预期的输出和原始数据
标签: javascript arrays lodash javascript-objects nivo-react