I currently have a chart that works statically, where I’ve preselected the year (2023) and code (A) in the chart, and I send an ID with a filter as shown below:
new ChartsEmbedSDK({}).createChart({
baseUrl: 'https://charts.mongodb.com/charts-project-55-hzzpo',
chartId: '651abc687',
showAttribution: false,
filter: {_id: ObjectID('xyz')}
});
More have a donut chart, that use the number of ‘num1’ and ‘num2’.
Now, I’m looking to make this process dynamic by allowing users to set the year and code variables in an aggregation query, and then use those variable values when calling the createChart
method.
Here are my questions:
- How can I make the year and code variables dynamic in the aggregation query and use their values with the
createChart
method?
- Here I tried to set new variable from
add fields
but not sure how it work, its not allowing.
- Is it possible to send the entire aggregation query along with the
createChart
request, so I can fully customize the data before rendering the chart?
For context, I’m working with a data schema like this:
[{
_id: 123,
entitle: {
"2003" : {
"A" : {
"num1" : 1,
"num2" : 2
},
// ...
},
// ...
}
}
// ...
]
Thank you for your assistance.