Filter by date using Charts SDK

I have a collection that, after applying some aggregation stages in the query ‘Query Bar’ ends up with documents containing three fields: _id, count and date. I created a columns chart correctly.

Using the Charts Embedding SDK for Javascript, I am embedding that column chart properly in a web page, but when I try to apply a range filter over the ‘date’ field (for instance, documents after a certain date) the resultant chart is not as expected.

What is the correct way of filtering by range for a date field using the Embedding SDK? I have tried these two ways:

  • filter['$gte'] = date
  • filter['$gte'] = new Date(date)

Thank you in advance :slight_smile:

Hi @Ricardo_Vasquez1 -

To filter on date fields, you should use regular JavaScript date objects. For example you could do something like this:

chart.setFilter( { released: { $gt: new Date("2010-01-01")}});

Remember that any fields you use on filters also need to be explicitly allowed in the Embed Chart dialog.

HTH
Tom

2 Likes

Hi Tom,

Thank you so much for your quick reply!
I just realized that my filter from the SDK was correct the whole time, and the problem was in aggregation steps that I was doing in the query bar (bad grouping).

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.