Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda