I have a json file with the following data which I would like to group by Year , Theme and then average values on each theme. Can someone help me with this? I have grouped by date and then theme but struggling after that.
[
{“Bid”:”BidTest1″,”QNo”:”1″,”Score”:”0.7″,”Theme”:”Social Value”,”QDate”:”01/01/2021″},
{“Bid”:”BidTest1″,”QNo”:”2″,”Score”:”0.5″,”Theme”:”Tech Mgt”,”QDate”:”01/01/2021″},
{“Bid”:”BidTest1″,”QNo”:”3″,”Score”:”0.8″,”Theme”:”Agile”,”QDate”:”01/01/2021″},
{“Bid”:”BidTest1″,”QNo”:”4″,”Score”:”0.7″,”Theme”:”Social Value”,”QDate”:”01/01/2021″},
{“Bid”:”BidTest456″,”QNo”:”1″,”Score”:”0.5″,”Theme”:”Tech Mgt”,”QDate”:”03/04/2021″},
{“Bid”:”BidTest456″,”QNo”:”2″,”Score”:”0.7″,”Theme”:”Social Value”,”QDate”:”03/04/2021″},
{“Bid”:”BidTest456″,”QNo”:”3″,”Score”:”0.5″,”Theme”:”Agile”,”QDate”:”03/04/2021″},
{“Bid”:”BidHO”,”QNo”:”1″,”Score”:”0.8″,”Theme”:”Agile”,”QDate”:”06/10/2021″},
{“Bid”:”BidHO”,”QNo”:”2″,”Score”:”0.7″,”Theme”:”Social Value”,”QDate”:”06/10/2021″},
]
The code I have used for grouping it is
let result1 = dataQ1.reduce((state1, current1 ) => {
let {QDate, Theme} = current1;
let date = state1[QDate] || (state1[QDate] = {});
let themeArr = date[Theme] || (date[Theme] = []);
// let monthArr = yearObj[month] || (yearObj[month] = []);
themeArr.push(current1);
return state1;
}, {});
This gives me an object with objects containing arrays for each Theme. I need to create a chart grouped by Month, Theme and mark the respective average values per theme.Final Data Sample.
Could someone please guide me on how to go about this ? Thanks