Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

342
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda