Skip to main content

VictoryLabel

VictoryLabel renders the label components that are used across all of Victory.

Component Props


angle

type: string | number

The angle prop specifies the angle to rotate the text around its anchor point.

Live View
Loading...
Live Editor

backgroundComponent

type: ReactElementdefault: <Rect/>

The backgroundComponent prop takes a component instance which will be used to create backgrounds for labels. The new element created from the passed backgroundComponent will be supplied with the following properties: x, y, height, width, style, and transform. Any of these props may be overridden by passing in props to the supplied component, or modified or ignored within the custom component itself. If backgroundComponent is omitted, a default Rect component will be created with props described above. backgroundComponent is only rendered when a backgroundStyle prop is added to VictoryLabel.

examples: backgroundComponent={<Rect height={50}/>}


backgroundPadding

type: number || array || { top: number, bottom: number, left: number, right: number }default: <Rect/>

The backgroundPadding prop adds padding around background elements. This prop may be given as a number or an object with values for "top", "bottom", "left", and "right". In the case of multi-line, multi-background labels, this prop may be given as an array.

Live View
Loading...
Live Editor

backgroundStyle

type: VictoryLabelStyleObject | VictoryLabelStyleObject[]

The backgroundStyle prop defines a set of SVG style properties that will be applied to the rendered background element(s). This prop should be given as an object, or array of objects. When this prop is given as an array of objects and there are multi-line labels, multiple background elements will be rendered, and styled individually. When this prop is given as an object, a single background element will be rendered for the entire label.

Live View
Loading...
Live Editor

capHeight

type: string | number | (args: CallbackArgs) => string | number

The capHeight prop defines a text metric for the font being used: the expected height of capital letters. This is necessary because of SVG, which (a) positions the bottom of the text at y, and (b) has no notion of line height. This prop should be given as a number of ems.


className

type: string

The className prop specifies a class name that will be applied to the rendered text element.


data

type: any[]

Victory components can pass a data prop to their label component. This can be useful in custom components that need to make use of the entire dataset.


datum

type: any

Victory components can pass a datum prop to their label component. This can be used to calculate functional styles, and determine text. If x and y are not specified, datum will be used to determine label position.


desc

type: string

The desc prop specifies the description of the chart/SVG to assist with accessibility for screen readers. The more descriptive this title is, the more useful it will be for people using screen readers.


direction

type: "rtl" | "ltr" | "inherit"default: "inherit"

The direction prop determines which text direction to apply to the rendered text element


dx

type: string | number | (args: CallbackArgs) => string | number

The dx prop defines a horizontal shift from the x coordinate.

Live View
Loading...
Live Editor

dy

type: string | number | (args: CallbackArgs) => string | number

The dy prop defines a vertical shift from the y coordinate. This prop is affected by capHeight, lineHeight, and verticalAnchor, and the number of lines of text that make up the label.

Live View
Loading...
Live Editor

events

type: array[object]

The events prop attaches arbitrary event handlers to the label component. This prop should be given as an object of event names and corresponding event handlers. When events are provided via Victory's event system, event handlers will be called with the event, the props of the component it is attached to, and an eventKey.

example: events={{onClick: (evt) => alert("x: " + evt.clientX)}}


groupComponent

type: ReactElement

The groupComponent prop takes a component instance which will be used to create group elements when VictoryLabel renders both labels and backgrounds.

default: <g/>


id

type: string | number | (args: CallbackArgs) => string | number

The id prop specifies a HTML ID that will be applied to the rendered text element.


inline

type: boolean

When the text property contains an array of strings, the inline property lets the <tspan /> elements lay out next to each other. If this property is not specified, the <tspan /> elements will stack vertically instead.

default: false

Live View
Loading...
Live Editor

labelPlacement

type: "parallel" || "perpendicular" || "vertical"

The labelPlacement prop is used to specify the placement of labels relative to the data point they represent. This prop may be given as "vertical", "parallel" or "perpendicular". This props is particularly useful in polar charts, where it may be desirable to position a label either parallel or perpendicular to its corresponding angle. When this prop is not set, perpendicular label placement will be used for polar charts, and vertical label placement will be used for cartesian charts.


lineHeight

type: string || number || function || array

The lineHeight prop defines how much space a single line of text should take up. Note that SVG has no notion of line-height, so the positioning may differ slightly from what you would expect with CSS, but the result is similar: a roughly equal amount of extra space is distributed above and below the line of text. This prop should be given as a number of ems.

Live View
Loading...
Live Editor

origin

type: { x: number, y: number }

Victory components will pass an origin prop is to define the center point in svg coordinates for polar charts. This prop should not be set manually.


polar

type: boolean

Victory components can pass a boolean polar prop to specify whether a label is part of a polar chart. This prop should not be set manually.


renderInPortal

type: boolean

The renderInPortal prop specifies whether VictoryLabel should render text in place or within a VictoryPortal. Setting renderInPortal to true is equivalent to wrapping VictoryLabel in a VictoryPortal. This prop is false by default.


scale

type: { x: scale, y: scale }

Victory components can pass a scale prop to their label component. This can be used to calculate the position of label elements from datum. This prop should not be set manually.


style

type: any[]

The style prop defines a set of SVG style properties that will be applied to the rendered <text/> element. This prop should be given as an object, or array of objects. When this prop is given as an array of objects, each style object in the array will be applied to the corresponding <tspan/> in multi-line labels. When this prop is given as an array with fewer elements than there are <tspan/> elements, the first element of the style array will be applied to extra lines.

Live View
Loading...
Live Editor

tabIndex

type: number | (args: CallbackArgs) => number

The tabIndex prop specifies the tabIndex that will be applied to the rendered label. This prop may be given as a number or as a function that returns a number.


text

type: string | string[]| number | (args: CallbackArgs) => string | number

The text prop defines the text VictoryLabel will render. The text prop may be given as a string, number, a function of datum, or an array of any of these. Strings may include newline characters, which VictoryLabel will split into separate <tspan/> elements. When text is given as an array, separate <tspan/> elements will be created for each element in the array.

examples: text={(datum) => "x: " + datum.x}, text="Apples\n(green)", text={["first line", "second line"]}

Live View
Loading...
Live Editor

textComponent

type: ReactElementdefault: <Text />

The textComponent prop takes a component instance which will be used to create text elements when VictoryLabel renders labels.


textAnchor

type: "start" || "middle" || "end" || "inherit" || function

The textAnchor prop defines how the text is horizontally positioned relative to the given x and y coordinates. Options are "start", "middle", "end", and "inherit". This prop may also be given as a function that returns one of these options.

Live View
Loading...
Live Editor

transform

type: string | object | function

The transform prop applies a transform to the rendered <text> element. This prop may be supplied as a string or an object containing transform definitions.

Live View
Loading...
Live Editor

verticalAnchor

type: "start" | "middle" | "end"

The verticalAnchor prop defines how the text is vertically positioned relative to the given x and y coordinates. Options are "start", "middle" and "end". This prop may also be given as a function that returns one of these options.

Live View
Loading...
Live Editor

x

type: number

The x prop defines the x coordinate to use as a basis for positioning the label element. Please note that this prop should be given in terms of svg coordinates, not data coordinates. To add a label annotation to a chart that is fixed to a specific data coordinate, please use the scale prop that VictoryChart provides to its children to transform data coordinates into svg coordinates.

Live View
Loading...
Live Editor

y

type: number

The y prop defines the y coordinate to use as a basis for positioning the label element. Please note that this prop should be given in terms of svg coordinates, not data coordinates.