Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
How to get an array from sequalize and insert into chart.js?

I want to get data (my output) from database and set it into chartjs by month. Like Month 5 (May) have 1 orders. I think they most be first mapped and setting into chart.js. Or i can make two arrays and set all information there in and then set it into the chartjs, but i dont know how.

delivered = await Order.findAll({ where: {status: 'DELIVERED',}, attributes: [
                        [Order.sequelize.fn('MONTH', Order.sequelize.col('created_at')), 'month'],
                        [Order.sequelize.fn('COUNT', Order.sequelize.col('id')), 'orders']
                    ], group: [Order.sequelize.fn('MONTH', Order.sequelize.col('created_at'))]},
                {where: {[Order.sequelize.fn('YEAR', Order.sequelize.col('created_at'))]: moment().format('YYYY')}})
               .catch((err) => {
                });
 

    

    const ctx = document.getElementById('myChart').getContext('2d');
    const myChart = new Chart(ctx, {
        type: 'line',
        data: {
            labels: [
                'January',
                'February',
                'March',
                'April',
                'May',
                'June',
                'July',
                'August',
                'September',
                'October',
                'November',
                'December',
            ],
            datasets: [
                {
                    label: 'Number of Deliveries per month',
                    data: [],
                    borderColor: '#4dc9f6',
                    backgroundColor: '#f67019',
                    tension: 0.2,
                },
            ],
            options: {
                responsive: true,
                plugins: {
                    legend: {
                        position: 'top',
                    },
                    title: {
                        display: true,
                        text: 'Chart.js Line Chart',
                    },
                },
            },
        },
    });


My output:
order {
    dataValues: { month: 5, orders: 1 },
    _previousDataValues: { month: 5, orders: 1 },
    uniqno: 1,
    _changed: Set(0) {},
    _options: {
      isNewRecord: false,
      _schema: null,
      _schemaDelimiter: '',
      raw: true,
      attributes: [Array]
    },
    isNewRecord: false
  }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!