useXAxisInverseDataSnapScale
Returns a function to convert pixel coordinates back to data values for an XAxis, but snapping to the closest data point. This is similar to useXAxisInverseScale, 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 Available since Recharts 3.8undefined if used outside a chart context, or if the axes don't exist.
Return value
InverseScaleFunction | undefined
An inverse scale function that maps pixel coordinates to the closest data value, or undefined.
Props
xAxisIdnumber | stringoptional
The
xAxisIdof the XAxis. Defaults to0if not provided.默认值:
"defaultAxisId"