Show "no matching data" rather than having a blank chart
I have a dashboard containing several charts. We also added filtering (which is complex and I had to build my own UI, which seems redundant - see https://feedback.mongodb.com/forums/923524-charts/suggestions/43736778-embedding-charts-with-filter-ui). In some cases, the user could create filters that end up filtering out all of the data. Strangely, this causes all of the charts in the dashboard to render completely blank. I would expect that, for example, a table would have all of its data replaced with zeroes, and a map might show without any of the countries being shaded. But instead, it's all blank, with no message of any kind.
To deal with this case, I had to jump through several hoops.
First, there is no event that I can find (and I read through the source!) that we can hook into that fires when data for each chart is downloaded. As the documentation specifies, when you call render()
on a Dashboard
object in the SDK, even after I await
the call, getData
on the Dashboard
's Chart objects will return an empty array. Considering this has no workaround in the documentation, I'd call that a bug, but it's related to this request.
So, I set a timer with setInterval
so that every second, I iterate over all the charts in the dashboard and call getData()
on each one. If, at some point, the getData()
calls returned some data, and now they no longer do, then I hide the entire dashboard and replace it with a message that says that the filters don't match any data. This was more code than I had to write in order to embed the whole dashboard! Please provide some workaround.