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

216
Visualizações
Lost column of bar chart in Chart.js

I display bar chart by chart.js but I get some problems. This is my data array data: [80, 81, 80, 64, 65, 80, 70, 75, 67, 85, 66, 50]. The last data value is 50 or 10 or 20 and it does not display ( Picture 1 ). If I change to 50.5 or 10.5, it can display but it is too small ( Picture 2 ). Anyone who knows my problem please help me. Thank you so much.

Here is my code :

//WidgetChart 5
    var ctx = document.getElementById("widgetChart5");
    if (ctx) {
      ctx.height = 220;
      var myChart = new Chart(ctx, {
        type: 'bar',
        data: {
          labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
          datasets: [
            {
              label: "My First dataset",
                  data: [80, 81, 80, 64, 65, 80, 70, 75, 67, 85, 66, 50.5],
              borderColor: "transparent",
              borderWidth: "0",
              backgroundColor: "#ccc",
            }
          ]
        },
        options: {
          maintainAspectRatio: true,
          legend: {
            display: false
          },
          scales: {
            xAxes: [{
              display: false,
              categoryPercentage: 1,
              barPercentage: 0.75
            }],
            yAxes: [{
              display: false
            }]
          }
        }
      });
    }

Picture 1 : The last data value ( 50 ) does not display enter image description here

Picture 2 : Now if change to 50.5 it is still too smal enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I can't tell for certain based on your screenshot, but I suspect that the chart is actually much taller than you can see but it is being hidden by its container (perhaps with overflow hidden). If you turn off the "responsive" option on the chart then you might find that you're able to see the entire chart. I've found that the "responsive" option usually means that the chart is much taller than I'd expect.

//WidgetChart 5
var ctx = document.getElementById("widgetChart5");
if (ctx) {
  ctx.height = 220;
  var myChart = new Chart(ctx, {
    type: 'bar',
    data: {
      labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
      datasets: [{
        label: "My First dataset",
        data: [80, 81, 80, 64, 65, 80, 70, 75, 67, 85, 66, 50],
        borderColor: "transparent",
        borderWidth: "0",
        backgroundColor: "#ccc",
      }]
    },
    options: {
      responsive: false,
      maintainAspectRatio: true,
      legend: {
        display: false
      },
      scales: {
        x: {
          display: false,
          categoryPercentage: 1,
          barPercentage: 1
        },
        y: {
          display: false
        }
      }
    }
  });
}
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<canvas id=widgetChart5 height="240" width="320"></canvas>

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