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

290
Views
Chart.js date formatting use for

How would I format data using for() and putting that data inside datasets in Chart.js.
I tried and it's only showing the date labels and not the marks, but when I add data manually without using the data from inside for() everything works like it should.

var date = [];
var marks = [];

for (var i in data) {
  date.push(data[i].timestamp); // timestamp
  marks.push(data[i].count); // votes 
}
new Chart('myChart', {
  type: 'line',
  data: {
    datasets: [{
      label: 'votes',
      data: [{
          'date': '11/11',
          'votes': 55
        },
        {
          'date': '5/11',
          'votes': 13
        }
      ],
      borderColor: 'grey',
      backgroundColor: 'rgba(0, 0, 255, 0.5)'
    }]
  },
  options: {
    parsing: {
      xAxisKey: 'date',
      yAxisKey: 'marks'
    },
    scales: {
      y: {
        ticks: {
          stepSize: 1
        }
      },
      x: {
        type: 'time',
        time: {
          parser: 'DD/MM/YY',
          unit: 'day',
          tooltipFormat: 'MMM DD'
        }
      },
      xAxes: [{
        type: 'time',
        time: {
          unit: 'month'
        }
      }],
    }
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I have it working now, just need to find a way to format the date without using numeric format. I think the reason it wasnt working at first is cause i was using an outdated version of chart.js.

var data = <?php print_r(json_encode($data)) ?> ;
var dates = [];
var vote = [];

for (var i in data) {
    dates.push(data[i].timestamp);
    vote.push(data[i].count);
}

var data = {
    labels: dates,
    type: "line",
    datasets: [{
        backgroundColor: '#585b72d9',
        data: vote,
    }],

};

var myBarChart = Chart.Line("examChart", {
    data: data,
});
about 4 years ago · Juan Pablo Isaza 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!