How to change the label in recharts?

Viewed 1132
 <BarChart
      isAnimationActive={false}
        width={400}
        height={200}
        data={value}
        margin={{
          top: 5, right: 30, left: 20, 
        }}
      >
        <CartesianGrid strokeDasharray="3 3" />
        <XAxis dataKey="x" 
        
        />
        <YAxis label={{ value: `no.`, angle: -90, position: 'insideBottomLeft' }} />
        <Tooltip
        content={<CustomTooltip />}
    />
   <Bar dataKey="y" /* fill={colors[0]} */ >
</BarChart>

My data on x axis is numerical [0,1,2,3...] but I want my ticks to be [A1,A2,A3...]

2 Answers

you can use formatter attribute, here is an example

<XAxis dataKey="x" tickFormatter={(t) => `A${t+1}`}   />

Change your value key

const value = [
  {
    x: 'A1', ......
  },
  {
    x: 'A2', .....
  },
]

Or you can use this:

<XAxis 
  dataKey="x"
  tickFormatter={(t) => {
       const count = parseInt(t) + 1
       return 'A'+ count;
      }
  }
/>
Related