Mastering Development

MongoDB Atlas stacked columns chart make array items count as it’s fractions

I’m trying to create a stacked column chart in MongoDB Atlas Charts, and I have an array which looks like that:

surveySource: [

So I’m just storing the user’s response to our survey in an array, as the user can select multiple options. When trying to make a stacked chart in mongoDB and selecting the unwind option, it count each array element as 1 "entry", however is there any way to make them count, for example, like 0.33 if the user selected 3 options total, e.g. so I want them to be counted not as one but as 1/array.length.

For example, let’s say there are two arrays:
["Instagram", "ad"], ["ad", "Influencer", "Instagram"], with the unwind option it’s counting them as follows: Ad – 2, Influencer – 1, Instagram – 2. But I want them counted as Ad – 0.83(0.5 + 0.33) Influencer – 0.33, Instagram – 0.83.

So my chart, that now looks like this, should have float numbers.

Leave a Reply

Your email address will not be published. Required fields are marked *