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

176
Views
Display a button in X axis with recharts

I have to create a bar chart using recharts. In the X axis I need to display the label and a button linked to each particular bar in order to do an action.

I found that it is possible to use more than a single X axis but I don't seem to find how to replace the dataKey to a component instead of a string. Any ideas?

Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I found information in recharts API https://recharts.org/en-US/examples/CustomizedLabelLineChart

It is possible to create a react component as long as it returns a element, and since it's possible to add an onClick function it can behave as a button. Here's the example:

class CustomizedAxisTick extends PureComponent {
  render() {
    const { x, y, stroke, payload } = this.props;

    return (
      <g transform={`translate(${x},${y})`} onClick={()=> console.log(payload.value)}>
        <text x={0} y={0} dy={16} textAnchor="end" fill="#666" transform="rotate(-35)">
          {payload.value}
        </text>
      </g>
    );
  }
}

then you just need to call the component in the XAxis like this:

<XAxis tick={<CustomizedTick />} />
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!