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

224
Views
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 answers
Answer question

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 Report
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!