Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda