useYAxisInverseTickSnapScale

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

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 tick.

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

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 tick value, or undefined.

Props

  • yAxisIdnumber | stringoptional

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

    默认值:"defaultAxisId"