useYAxisInverseDataSnapScale

Returns a function to convert pixel coordinates back to data values for a YAxis, but snapping to the closest data point.

This is similar to useYAxisInverseScale, but instead of returning the exact data value at the pixel position (interpolation), it returns the value of the closest data point.

This is useful for implementing interactions where you want to select the closest data point rather than an exact value or a tick.

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 the closest data value, or undefined.

Props

  • yAxisIdnumber | stringoptional

    The yAxisId of the YAxis. Defaults to 0 if not provided.

    默认值:"defaultAxisId"