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

253
Views
Chart JS how to display an array of data objects as bar chart

I want to display a bar chart - each bar is a user/student. And for each student, there will be an xAxis label displaying the students name

The below code is a VueJS computed property and called chartData

My data array for the bar chart is an array of objects. Here is how i generate it

let dataRow = this.responses.map((d) => {
  return {
    label: d.user.name,
    data: [d.grade],
  }
});

Here is how I generate my labels

let users = [];
this.responses.map((d) => {
  users.push(d.user.name)
});

I then return on object with an array of labels and datasets with data being an array of objects

return {
  labels: users,
  datasets: [{
    data: dataRow
  }],
}

Here is how I render the chart:

{
  extends: Bar,
  props: ["chartdata"],
  data() {
    return {
      options: {
        responsive: true,
        maintainAspectRatio: false,
        scales: {
          yAxes: [{
            ticks: {
              beginAtZero: true,
              max: 100
            }
          }],
        },
      }
    }
  },
  mounted() {
    this.renderChart(this.chartdata, this.options)
  }
}

Issue: Nothing displays and there are no errors

The bar chart only seems to work when the data in the datasets is not an array of object like:

testData: {
  labels: ['test', 'test', 'test'],
  datasets: [{
    data: [65, 59, 80],
  }]
}

After Sayf-Eddine comment, i have managed to achieve this:

enter image description here

I changed how i returned the chartdata like:

return {
      labels: users,
      datasets: dataRow
}

However, all bars are mapping to the first label

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After Vitaliy Rayets comment i figured out what was wrong

i needed to return the data row like:

let dataRow = this.responses.map((d) => {
  return {
    label: d.user.name,
    y: [d.grade],
  }
});

**I changed the property 'data' to 'y' **

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!