Hooks for converting between data values and pixel coordinates.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/recharts/recharts/llms.txt
Use this file to discover all available pages before exploring further.
useXAxisScale
Returns a function to convert data values to pixel coordinates for an X-axis. Useful for positioning annotations, custom shapes, or other elements at specific data points on the chart.The ID of the X-axis. Defaults to
0 if not provided.A scale function that maps data values to pixel coordinates, or
undefined if used outside a chart context or if the axis doesn’t exist.useYAxisScale
Returns a function to convert data values to pixel coordinates for a Y-axis. Useful for positioning annotations, custom shapes, or other elements at specific data points on the chart.The ID of the Y-axis. Defaults to
0 if not provided.A scale function that maps data values to pixel coordinates, or
undefined if used outside a chart context or if the axis doesn’t exist.useCartesianScale
Converts a data point (in data coordinates) to pixel coordinates. This is a convenience hook that combinesuseXAxisScale and useYAxisScale together in a single call.
The data point with x and y values in data coordinates.
The ID of the X-axis. Defaults to
0 if not provided.The ID of the Y-axis. Defaults to
0 if not provided.Object with pixel x and y coordinates, or
undefined if conversion is not possible.Inverse scale hooks
Convert pixel coordinates back to data values.useXAxisInverseScale
Returns a function to convert pixel coordinates back to data values for an X-axis. 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.The ID of the X-axis. Defaults to
0 if not provided.An inverse scale function that maps pixel coordinates to data values, or
undefined.- For continuous (numerical) scales: returns an interpolated value
- For categorical scales: returns the closest category in the domain (same as
useXAxisInverseDataSnapScale)
useYAxisInverseScale
Returns a function to convert pixel coordinates back to data values for a Y-axis.The ID of the Y-axis. Defaults to
0 if not provided.An inverse scale function that maps pixel coordinates to data values, or
undefined.Snap scale hooks
Snap to the closest data point or tick instead of interpolating.useXAxisInverseDataSnapScale
Returns a function to convert pixel coordinates back to data values, snapping to the closest data point. Similar touseXAxisInverseScale, but instead of returning the exact data value at the pixel position (interpolation), it returns the value of the closest data point.
The ID of the X-axis. Defaults to
0 if not provided.An inverse scale function that maps pixel coordinates to the closest data value, or
undefined.useYAxisInverseDataSnapScale
Returns a function to convert pixel coordinates back to data values for a Y-axis, snapping to the closest data point.The ID of the Y-axis. Defaults to
0 if not provided.An inverse scale function that maps pixel coordinates to the closest data value, or
undefined.useXAxisInverseTickSnapScale
Returns a function to convert pixel coordinates back to data values, snapping to the closest axis tick. Similar touseXAxisInverseScale, but instead of returning the exact data value at the pixel position (interpolation), it returns the value of the closest tick.
The ID of the X-axis. Defaults to
0 if not provided.An inverse scale function that maps pixel coordinates to the closest tick value, or
undefined.useYAxisInverseTickSnapScale
Returns a function to convert pixel coordinates back to data values for a Y-axis, snapping to the closest axis tick.The ID of the Y-axis. Defaults to
0 if not provided.An inverse scale function that maps pixel coordinates to the closest tick value, or
undefined.Types
ScaleFunction
value- The data value to convert (number, string, or category)options.position- Position within a band: ‘start’, ‘middle’, or ‘end’- Returns the pixel coordinate, or
undefinedif the value is not in the domain
InverseScaleFunction
pixelValue- The pixel coordinate to convert- Returns the closest data value in the domain