useXAxisInverseScale

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

This is useful for implementing interactions like click-to-add-annotation, drag interactions, or tooltips that need to determine what data point corresponds to a mouse position.

For continuous (numerical) scales, returns an interpolated value. For categorical scales, returns the closest category in the domain - which is the same behaviour as useXAxisInverseDataSnapScale.

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

InverseScaleFunction | undefined

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

Props

  • xAxisIdnumber | stringoptional

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

    DEFAULT: "defaultAxisId"