Render chart using mongoDB and chart.js

0

Hello, I have a question on how to render a chart with chart.js using mongo data.

I've already been able to render one, but I'm having trouble rendering another, probably due to how the data is returning.

The query is as follows:

const testeAtM = atendimentos.aggregate([
            {
                '$group':
                    {
                        '_id':
                            {'id_atendente': "$id_atendente", 'month': {'$month': '$date'}},
                        'sum': {'$sum': 1}
                    }
            },
            {'$sort': {'_id': 1}},
            {
                '$group': {
                    '_id': null,
                    'testatm': {'$push': '$$ROOT'}
                }
            },
        ]).exec();

This variable testatm is the key, I already rendered a graph in this way but what it returned was just a number, it worked correctly.

This query returns the data in this format:

"testatm" : [ 
{ "_id" :
{ "id_atendente" : 0,
"month" : 4 },
"sum" : 5 },
{ "_id" :
{ "id_atendente" : 0,
"month" : 5 },
"sum" : 17 } ... ]

This data is initially available on the front end, since I can render a table through them. I'm sending the data through a promise.

I would like to know how to render them using the chart, I already tried to put in the date field as I did with the other chart and it did not work.

NOTE: I am using node and my template is EJS.

Thanks to anyone who can help!

    
asked by anonymous 20.08.2018 / 15:04

0 answers