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

128
Visualizações
how to pass a list of dictionary in chartjs labels and data?

I'm trying to show my data into chart js graph, my data format is this:

> {length: 3, objects: Array(3)}
length: 3
objects: Array(3)
0: {counter: 1, date: '2022-06-01 00:00:00', income: '233.000', …}
1: {counter: 2, date: '2022-05-01 00:00:00', income: '1000.000', …}
2: {counter: 3, date: '2022-04-01 00:00:00', income: '89.000', …}
length: 3
[[Prototype]]: Array(0)
[[Prototype]]: Object

here is what i tried in my js:

        function listChartMonOutcome(){
            $.ajax({
                type:'GET',
                url:'/listcharts/data/',
                success:function(data){
                    var totalMonthCanvas = $('#listChart').get(0).getContext('2d')
                    var totalMonthData = {
                      labels: [
                        data
                      ],
                        data:{
                            datasets:[{
                                data:[{
                                    data
                                }]
                            }]
                        }
                      
                    }
                    var totalMonthOptions     = {
                      responsive              : true,
                      maintainAspectRatio     : false,
                      datasetFill             : false,
                      parsing: {
                        xAxisKey: 'income',
                        yAxisKey: 'date'
                    }                
                    }
                    var totalMonthChart = new Chart(totalMonthCanvas, {
                      type: 'bar',
                      data: totalMonthData,
                      options: totalMonthOptions      
                    })
                }
            })                
            }
            listChartMonOutcome()            
        }
              <div class="card-body">
                <div class="chart">
                  <canvas id="listChart" style="height:250px; min-height:250px"></canvas>
                </div>
              </div>

but it shows nothing, in the console as well.

and also tried this in the data :

labels = [data.map(({datE}) => date) ]
datasets: [
   {
      data: [
          data.map(({income}) => income)                            
      ],
   }
 ]

but raise this error:

Uncaught TypeError: data.map is not a function

is there any solution for this problem please?

Thank you for helping

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