I'm trying to build some Heatmap specifics charts for ApexChart. So far, I got this Array of Hash, for 3 activities.
[{
:name => "Activity 1",
:data => {
"May 2020" => 37, "June 2020" => 17, "July 2020" => 9, "August 2020" => 18
}
}, {
:name => "Activity 2",
:data => {
"May 2020" => 3
}
}, {
:name => "Activity 3",
:data => {
"July 2020" => 5, "November 2020" => 11
}
}]
On Activity 3, we got only 2 months which are, July
and November
.
My needs would be to fill for each Hash, all missing date, and filling them with 0 as value. My awaited results would be
[{
:name => "Activity 1",
:data => {
"May 2020" => 37, "June 2020" => 17, "July 2020" => 9, "August 2020" => 18, "November 2020" => 0
}
}, {
:name => "Activity 2",
:data => {
"May 2020" => 3, "June 2020" => 0, "July 2020" => 0, "August 2020" => 0, "November 2020" => 0
}
}, {
:name => "Activity 3",
:data => {
"May 2020" => , "June 2020" => 0, "July 2020" => 5, "August 2020" => 0, "November 2020" => 11
}
}]
Yes, September
is missing on purpose. I suppose the best way to achieve this would be to retrieve every months, one by one; Then to fill each arrays with the missing months; But I don't know how to achieve this.