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

628
Views
Unaligned x scales for two Chartjs-chart types with the same configuration - only difference is "chart type" (bar/line)

I built a line chart & a bar chart in Chartjs with exactly the same configuration, but for some reason the x-scales of both charts are different as you can see in the picture below.

enter image description here

The configuration for the both charts is the same, the only difference is the chart type:

function getOptions() {
    return {
        animation: false,
        responsive: true,
        maintainAspectRatio: false,
        plugins: {
            tooltip: false,
            legend: {
                display: false
            },
            title: {
                display: false
            }
        },
        elements: {
            line: {
                fill: true
            },
            point: {
                radius: 0
            }
        },
        scales: {
            x: {
                type: "time",
                time: {
                    displayFormats: {
                        second: 'HH:mm:ss',
                        minute: 'HH:mm',
                        hour: 'HH'
                    },
                    unit: 'minute',
                    stepSize: 1,
                    min: '00:00:00',
                    max: '23:59:59',
                },
                grid: {
                    display: true,
                    drawBorder: true,
                    drawOnChartArea: true,
                    drawTicks: true,
                    color: function(context) {
                        return '#fff';
                    },
                }
            },
            y: {
                beginAtZero: true,
                grid: {
                    display: true,
                    drawBorder: false,
                    color: function(context) {
                        return '#fff';
                    },
                },
            }
        }
    };
}

I noticed that the x axes do align perfectly, if I set the "stepSize" to 'seconds'. This probably has to do with the fact that the data inserted into the chart is second-data.

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

0

This is because the bar chart sets the offset property on the x axis scale to true.

https://www.chartjs.org/docs/3.8.0/axes/cartesian/category.html#common-options-to-all-cartesian-axes

So to align them you either have to set it to false for the bar chart or to true for the line chart

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!