Time based charts

Hi! I’m trying to include some time-based charts in my dashboard. I have an “order” model with various properties. The ones relevant for this chart would be creationDate property which is a timestamp, and a total object that has a price.

Expected behavior

To be able to create time-based charts that sum the price value value and a count chart to simply get the order creation rate over time.

Actual behavior

When I click Time based charts and select the collection, I’m unable to select the value or group by options. They appear as empty dropdowns.

Context

Please provide any relevant information about your setup.

  • Package Version: 3.6.5
  • Express Version:
  • Sequelize Version:
  • Database Dialect: MongoDB
  • Database Version: 4.2.8
  • Project Name: Tranki



Hi @Henry_O,

About price, as you mentioned, it is not a direct attribute of an order but an embedded field in total object, that is the reason why it is not available as an aggregation field to sum. It is a feature we have for direct attributes only.

About creationDate, it looks like this field is detected as a “String” (not a “Date”) on our end, it might explain why this field is not available in the “Group by” select.

Could you share you schema definition for the Orders collection to confirm this?

From my point of view, with your current data structure, the only way to achieve what you want in Forest Admin is to use a “Smart” data source (ie a Smart Chart).

Hope it helps.

Hey @arnaud! Thanks for the info. Indeed total is a sub-document and creationDate is actually a timestamp represented as a string. Good thing we are not live yet so we can easily make those changes. If this fails we will try the smart charts.

Thanks!

1 Like

Hey @arnaud! I’m having another issue now that we’ve implemented the changes you recommended.

We are now able to select creationDate as time factor and price in order to sum all of them together. However, I’m getting this error in the console: (0 , _moment.default)(...).tz is not a function

Here’s an order object so you check it out.

/** 
* Paste one or more documents here
*/
{
    "status": "unfulfilled",
    "cart": [{
        "_id": {
            "$oid": "5f784360f121c4d731af0cbd"
        },
        "productID": "B0199ANV1G",
        "image": "https://images-na.ssl-images-amazon.com/images/I/514iLbGzE1L.jpg",
        "title": "Huy Fong, Sriracha Hot Chili Salsa, 9 onzas botella (2 unidades) por Sriracha",
        "price": "11.76",
        "qty": 1,
        "link": "https://www.amazon.com/-/es/Sriracha-Chili-onzas-botella-unidades/dp/B0199ANV1G",
        "variant": "MAIN",
        "supplier": {
            "name": "Amazon"
        }
    }],
    "userID": "xxxxxxxxxxxxxx",
    "email": "someemail@gmail.com",
    "phoneNumber": "+34555555",
    "price": 21.75,
    "payment": {
        "txID": "xxxxxx",
        "method": "Stripe",
        "last4": "1111",
        "brand": "MasterCard"
    },
    "shipping": {
        "address": {
            "_id": {
                "$oid": "5f784360f121c481f9af0cbe"
            },
            "country": "Venezuela",
            "firstName": "Carlos Enrique",
            "lastName": "Suito",
            "phoneNumber": "+34555555",
            "street": "Ronda de Sant Antoni, 80",
            "houseOrAptNumber": "Atico",
            "city": "Caracas",
            "state": "Distrito Capital",
            "municipality": "Ciutat Vella",
            "postCode": "08001",
            "additionalInfo": "Tocar intercomunicador"
        },
        "courier": "Tiger shipping",
        "method": "sea",
        "weight": "1.37",
        "dimensions": "0.33",
        "total": {
            "cost": 4.95,
            "price": 10
        },
        "eta": "3 de noviembre",
        "timeline": []
    },
    "creationDate": {
        "$date": "2020-10-03T09:24:48.216Z"
    },
    "updatedOn": {
        "$date": "2020-10-03T09:24:48.216Z"
    },
    "__v": 0
}

So basically, creationDate is of type Date, but for some reason it’s messing up forest’s charts. Any ideas how might I solve this problem?

Thanks!