Hi there,
I’m new to MongoDB charts and have done a search for answers via the community but cannot find the one I am looking for.
I have set up my chart as unauthenticated and using 2 fields to display data:
- rating
- date
I also want to filter via the field ‘user’ which contains the user id for the logged-in user.
If I filter this via the MongoDB chart dashboard it works fine. But if I set this via the SDK, it doesn’t show the chart at all on my web application.
I’ve tried to test this using:
*filter: { “user”: { “$match”: ‘63c18143c9379120a15b935e’ } }
*chart.setFilter({“user”: { “$match”: ‘63c18143c9379120a15b935e’ }}.
I’ve tried without the $match for both also {“user”: “63c18143c9379120a15b935e”} and nothing is displayed.
It works fine without setting the filters.
Can someone help and explain what I’m doing wrong, do I need a token?
Many thanks
Kirstie
Here’s the code:
const sdk = new ChartsEmbedSDK({
baseUrl: 'This is where I've placed my Chart url'
});
const chart = sdk.createChart({ chartId: 'This is where I've placed my chart id',
height: "400px",
width:"100%",
showAttribution:false,
background:"transparent",
labels:false,
autoRefresh:true,
filter: { "user": { "$match": '63c18143c9379120a15b935e' } }
});
async function refresh(){
await chart.render(document.getElementById('chart'));
await chart.setAutoRefresh(true);
await chart.setMaxDataAge(30);
}
refresh()