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

227
Visualizações
Chart.js - parsing Object Array

Chart.js version - 3.8.0 (latest)

Hi all

Losing my mind with this at the moment. I have been able to successfully display the chart once. Since then it is failing to render and I have no idea why.

I have built an object array prior (counts lines in multiple csv files) to declaring the chart options and then passed this array in according to the examples on the chart js website.

I have output to console to ensure that the data is being loaded correctly and everything looks ok. Could someone please cast an eye over the code below and point out anything obvious?

const data = YTDTable; 

var ctx1 = document.getElementById('YTD').getContext('2d');

var myChart1 = new Chart(ctx1, {
type: 'bar',
data: {
    datasets: [{
        data: data,
        label: "Tickets to Date"
    }]
},
options: {
    parsing: {
        xAxisKey: 'month',
        yAxisKey: 'count'
    }
},
    });

This is the dataset output of console.log(myChart1.data) which is executed after the above codeblock:

{
    "datasets": [
        {
            "data": [
                {
                    "month": "January",
                    "count": 1629
                },
                {
                    "month": "February",
                    "count": 1832
                },
                {
                    "month": "April",
                    "count": 1626
                },
                {
                    "month": "May",
                    "count": 2034
                },
                {
                    "month": "March",
                    "count": 1802
                },
                {
                    "month": "June",
                    "count": 1585
                }
            ],
            "label": "Test"
        }
    ],
    "labels": []
}

I just don't understand why the above code isn't working. Any help is much appreciated

The chart output on screen: chart image - can't embed images yet...

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

OK, SO

I figured out what the problem was. The code does work. It just isn't rendering it straight away for some reason. If I resize the window it draws it to screen....

Oh well. Can fix that. Thanks for looking

UPDATE

I have identified the cause for the delay in the drawing of the chart and decide to update the answer in case anyone has a similar problem.

My chart code appeared to be executing before the data collected in YTDTable had finished. II have now removed the code block responsible for the data collection from the javascript file and placed it in a script block in the index page instead.

This causes the data collection to execute long before the chart code executes.

about 4 years ago · Santiago Gelvez Relatório
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