【发布时间】:2023-01-05 20:08:05
【问题描述】:
我正在尝试绘制一个图表来显示品牌的年度销售额比较,下面是两个年度销售额数组。
var current_year = [
{
total: 12941.17,
comapanyName: "Samsung",
year: "2021"
},
{
total: 17946.87,
comapanyName: "Haier",
year: "2021"
},
{
total: 3832.36,
comapanyName: "Beetel",
year: "2021"
},
{
total: 12528,
comapanyName: "Celkon",
year: "2021"
}
];
var last_year = [
{
total: 427805.51,
comapanyName: "Samsung",
year: "2020"
},
{
total: 77576.33,
comapanyName: "Godrej",
year: "2020"
},
{
total: 53389.02,
comapanyName: "Beetel",
year: "2020"
},
{
total: 100748.49,
comapanyName: "Celkon",
year: "2020"
},
{
total: 4534.19,
comapanyName: "FORD",
year: "2020"
},
{
total: 5.05,
comapanyName: "Voltas",
year: "2020"
}
];
由于一些公司名称在各自的数组中丢失,我无法按预期绘制图表。我需要帮助将缺少的公司名称添加到相应的数组中,包括年份、名称和总数。 类似于这张图https://apexcharts.com/react-chart-demos/line-charts/data-labels/
期待 -
- 公司“FORD”在 last_year 中存在但在 current_year 数组中缺失,在 current_year 数组中添加“FORD”对象 示例 = [{total:0, comapnyName:'FORD', year:2021}]
- 公司“Haier”存在于 current_year 数组中但在 last_year 数组中缺失,在 last_year 数组中添加“Haier” 示例 = [{total:0, comapnyName:"Haier", year:2020}]
【问题讨论】:
标签: javascript arrays charts apexcharts