Currently, I am working with two arrays that are the result of an API call.
The structure of the first array is as follows:
{
"data":[
{
"Total":[
3173.18
],
"currency":[
"USD"
],
"xaxis":[
"Feb 2022"
]
}
],
"id":"TotalPerMonth"
}
I need to fill in missing months in the xaxis
array by referencing another array that looks like this:
['Nov 2021', 'Dec 2021', 'Jan 2022', 'Feb 2022', 'Mar 2022', 'Apr 2022']
The complete API response contains multiple data sets and has this structure:
[
{
"data":[
{
"Item 1":[
0
],
"Item 2":[
0
],
...
}
],
...
},
{
"data":[
{
"Total":[
3173.18
],
...
}
],
...
}
]
My main concern is how to include the missing months in the xaxis
array, populate them with placeholder values in the Total
array, and make sure they are sorted correctly before being sent to ECharts?
An expected output could be:
{
"data":[
{
"Total":[
0,
0,
0,
3173.18,
0,
0,
],
"currency":[
"USD"
],
"xaxis":[
"Nov 2021",
"Dec 2021",
"Jan 2022",
"Feb 2022",
"Mar 2022",
"Apr 2022"
]
}
],
"id":"TotalPerMonth"
}