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

262
Views
Completely hide empty bars in chart.js

In my Chart.js bar chart, each label has about 6 datasets. Some of these datasets have the value "0". This results in empty gaps on the x-axis, see:

Three empty bars should get removed

I would like to remove these empty gaps. How should I do this?

After my code is rendered from the Database, it looks like this. Please note that for the sake of simplicity, I have reduced the code a lot so that it consists of only two years. The picture above shows only one year.

const labels = [2019, 2020];

const data = {
    labels: labels,
    datasets: [{
        label: 'Dataset 1',
        data: ['0','0']
    },
    {
        label: 'Dataset 2',
        data: ['0', '300']
    },
    {
        label: 'Dataset 3',
        data: ['0','360']
    },
    {
        label: 'Dataset 4',
        data: ['0','0']
    },
    {
        label: 'Dataset 5',
        data: ['0','0'],
    },
    {
        label: 'Dataset 6',
        data: ['0', '1020']
    }]
};

Replacing the "0" by "null" doesn't help. I need to include the "0" / "null", otherwise all datasets get shifted into the wrong year. However, as mentioned, I do not want to loose space therefore because the datasets are different per year and a lot more datasets will follow!

Should I render the datasets in a different style? Should I use a plugin to hide these empty spots?

Thank you so much!

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

0

I asked the same question over here:

How to prevent empty bars from taking up width in Chart.js bar chart

If your problem was the same as mine, you need to add skipNull to your dataset.

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!