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

176
Views
Chart.js v3 - beginAtZero does nothing to my chart

I read many threads on the beginAtZero parameter in Chart.js, but none of the solutions I found actually work for me.

I have a simple line chart with dates on my x axe and integers in my y axe. I can't manage to make my y axe start with 0.

 let atchoum = document.querySelector("#atchoum")
    let statchoum = new Chart(atchoum, {
        type: "line",
        data: {
            labels: {{ atchoumDate|raw }},
            datasets: [{
                label: "Nombre d'éternuements au support",
                data: {{ atchoumNb|raw }},
                borderColor: "blue",
                tension: 0.3,
                options: {
                    responsive: true,
                    scales: {
                       y: {
                           beginAtZero: true
                       }
                    },
                    animations: {
                        y: {
                            easing: 'easeInOutElastic',
                            from: (ctx) => {
                                if (ctx.type === 'data') {
                                    if (ctx.mode === 'default' && !ctx.dropped) {
                                        ctx.dropped = true;
                                        return 0;
                                    }
                                }
                            }
                        }
                    },
                }
            }]
        }
    })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are defining your options in the dataset itself. The options object is supposed to be on the same level as the type and data fields since the options are for the entire chart and not for a single dataset.

const options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
      label: '# of Votes',
      data: [12, 19, 7, 9, 20, 8]
    }]
  },
  options: {
    scales: {
      y: {
        beginAtZero: true
      }
    }
  }
}

const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.5.1/chart.js"></script>
</body>

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!