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

177
Views
Chart.js configuration

I have a bar chart created in chart.js and its config is below:

import Chart from 'chart.js/auto';

document.addEventListener("turbo:load", function(e) {
  let manufacturersPieChartCanvas = document.getElementById('manufacturers-pie-chart');

  if (manufacturersPieChartCanvas) {
    let labels = JSON.parse(manufacturersPieChartCanvas.dataset.manufacturers_chart_labels);
    let data = JSON.parse(manufacturersPieChartCanvas.dataset.manufacturers_chart_data);

    const config = {
      type: 'bar',
      data: {
        labels: labels,
        datasets: [{
          backgroundColor: ['yellow', 'red', 'green', 'blue'],
          data: data,
          hoverOffset: 4
        }]
      },
      options: {
        responsive: true,
        categoryPercentage: 1,
        barPercentage: 0.8,
        scaleShowValues: false,
        indexAxis: 'y',
        scales: {
          yAxes: [{
            ticks: {
              autoSkip: false
            }
          }]
        }
      }
    };

    let manufacturersPieChart = new Chart(
      manufacturersPieChartCanvas,
      config
    );
  }
})

A portion of it looks like so:

enter image description here

I am trying to allow ALL the bar titles to show up. I have followed suggestions on SO, in regards to autoSkip false but they don't seem to have any effect. For this chart, it is imperative that all bar titles display all the time. Also, i'd prefer the height to be increased to make each bar slightly thicker. I have tried with config options and can make them thicker but the overall chart area doesn't increase to accommodate them?

Any suggestions to fix these issues?

Thanks.

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

0

You are trying to define your scales in V2 syntax while using V3, I advise reading the migration guide first if you are transfering from V2.

To make the bars a bit thicker you can increase the barPercentage and categoryPercentage to 1 but this will remove all the space between the bars. The only other option to make them bigger is by giving the chart actually more space by making the canvas bigger using CSS

var options = {
  type: 'bar',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
        label: '# of Votes',
        data: [12, 19, 3, 5, 2, 3],
        backgroundColor: 'pink',
        barPercentage: 1,
        categoryPercentage: 1
      },
      {
        label: '# of Points',
        data: [7, 11, 5, 8, 3, 7],
        backgroundColor: 'orange',
        barPercentage: 1,
        categoryPercentage: 1
      }
    ]
  },
  options: {
    indexAxis: 'y',
    scales: {
      y: {
        ticks: {
          autoSkip: false
        }
      }
    }
  }
}

var 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!