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

343
Views
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 answers
Answer question

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