useXAxisScale

Returns a function to convert data values to pixel coordinates for an XAxis.

This is useful for positioning annotations, custom shapes, or other elements at specific data points on the chart.

This hook must be used within a chart context (inside a LineChart, BarChart, etc.). Returns undefined if used outside a chart context, or if the axes don't exist.

Available since Recharts 3.8

Return value

ScaleFunction | undefined

A scale function that maps data values to pixel coordinates, or undefined.

Props

  • xAxisIdnumber | stringoptional

    The xAxisId of the XAxis. Defaults to 0 if not provided.

    默认值:"defaultAxisId"