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

337
Visualizações
make horizontal graph with percentage :react js

I trying to make a horizontal chart with react-chartjs i want each data to show the percentage

import React, { Component } from "react";

import { HorizontalBar } from "react-chartjs-2";
export default class Button extends Component {
  render() {
    const dataHorBar = {
      labels: ["January", "February", "March", "April", "May", "June", "July"],
      datasets: [
        {
          label: "My First dataset",
          backgroundColor: "#EC932F",
          borderColor: "rgba(255,99,132,1)",
          borderWidth: 1,
          hoverBackgroundColor: "rgba(255,99,132,0.4)",
          hoverBorderColor: "rgba(255,99,132,1)",
          data: [65, 59, 80, 81, 56, 55, 40]
        }
      ]
    };
    return (
      <div>
        <HorizontalBar data={dataHorBar} />
      </div>
    );
  }
}

enter image description here

Here is the code of what I have tried

https://codesandbox.io/s/react-chartjs-bar-horizontal-bar-forked-be9wil

I also want to remove the background lines and make the graph more rounded edge

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

0

In order to use the feature for having rounded rectangles, you need to update to the v3 of chartjs, therefore, the following code will be working only on this version. But you can adapt it to a previous version, you will just not be able to change the border radius of the rectangle.

You can use the datalabels plugin, in order to display custom text in your chart, and format the label like this:

options: {
    plugins: {
      datalabels: {
        formatter: value => value + " %", // Add the percentage after the value
        align: "end",
        anchor: "end",
        clip: true,
      }
    }
  }

For the shapes, you can use the option borderRadius, to have rounded edges. You can find more information here, but in the end, you just have to specify a value for the borderRadius, in each dataset:

datasets: [
        {
          label: "My First dataset",
          backgroundColor: "#EC932F",
          borderColor: "rgba(255,99,132,1)",
          borderWidth: 1,
          hoverBackgroundColor: "rgba(255,99,132,0.4)",
          hoverBorderColor: "rgba(255,99,132,1)",
          data: [65, 59, 80, 81, 56, 55, 40],
          borderRadius: 50, // Give a number
        }
      ] 

Finally, for removing the grid lines, you can use this snippet, and pass those options to your chart

options: {
    scales: {
      x: {
        grid: {
          display: false // Hide x grid
        }
      },
      y: {
        grid: {
          display: false // Hide y grid
        }
      }
    }
  };

That's it for the ground principle. Here is a live working example, if you really wants to see how to implement it.

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