I am working on chart Area → Discrete layout
I have aggregation query for chart as collection names - usageCollection
[
{
$project: {
spendRebate: 1,
rebateCollected: 1,
facility: 1
}
},
{
$facet: {
rebateCollected: [
{
$unwind: {
path: "$rebateCollected"
// preserveNullAndEmptyArrays: false,
}
},
{
$match: {
"rebateCollected.amount": {
$exists: true,
$ne: null
}
}
},
{
$project: {
facility: 1,
rebateCollectedAmount: "$rebateCollected.amount",
rebateDate: "$rebateCollected.date"
}
},
{
$group: {
_id: {
facility: "$facility",
rebateDate: "$rebateDate"
},
totalRebatedAmount: {
$sum: "$rebateCollectedAmount"
}
}
},
{
$project: {
facility: "$_id.facility",
date: "$_id.rebateDate",
totalRebatedAmount: "$totalRebatedAmount",
_id: 0
}
}
],
spendRebateData: [
{
$unwind: {
path: "$spendRebate.payPeriod"
}
},
{
$project: {
_id: 1,
facility: 1,
endDate: "$spendRebate.payPeriod.window.end",
poAmount: "$spendRebate.payPeriod.spend",
rebateEarned: "$spendRebate.payPeriod.rebated"
}
},
{
$group: {
_id: {
endDate: "$endDate",
facility: "$facility"
},
totalPOAmount: {
$sum: "$poAmount"
},
totalRebatedEarned: {
$sum: "$rebateEarned"
}
}
},
{
$project: {
date: "$_id.endDate",
facility: "$_id.facility",
totalPOAmount: "$totalPOAmount",
totalRebatedEarned: "$totalRebatedEarned",
_id: 0
}
}
]
}
},
{
$project: {
data: {
$concatArrays: ["$spendRebateData", "$rebateCollected"]
}
}
},
{
$unwind: "$data"
},
{
$replaceRoot: {
newRoot: "$data"
}
},
{
$group: {
_id: {
facility: "$facility",
date: "$date"
},
totalPOAmount: {
$sum: "$totalPOAmount"
},
totalRebatedEarned: {
$sum: "$totalRebatedEarned"
},
totalRebateCollectedAmount: {
$sum: "$totalRebatedAmount"
}
}
},
{
$project: {
date: "$_id.date",
facility: "$_id.facility",
totalPOAmount: 1,
totalRebatedEarned: 1,
totalRebateCollectedAmount: 1
}
}
]
In the chart I have configuration as
X axis - date
Y axis - totalPOAmount
I added filter on field “facility”
We have two facilities “facilityA” and “facilityB”
Now on chart when facility is not selected , it needs to show data(totalPOAmount) summed up of facilityA and facilityB.
But in actual its showing only single facility data.