Chart primitives
Layouts & specialized
Interactions
Data utilities
Umbrella package
@vx/legend
Legends associate shapes and colors to data, and are associated with scales.
Example
import { LegendThreshold } from '@vx/legend';
import { scaleThreshold } from '@vx/scale';
const threshold = scaleThreshold({
domain: [0.02, 0.04, 0.06, 0.08, 0.1],
range: ['#f2f0f7', '#dadaeb', '#bcbddc', '#9e9ac8', '#756bb1', '#54278f'],
});
function MyChart() {
return (
<div>
<svg>{/** chart stuff */}</svg>
<LegendThreshold
scale={threshold}
direction="column-reverse"
itemDirection="row-reverse"
labelMargin="0 20px 0 0"
shapeMargin="1px 0 0"
/>
</div>
);
}
Installation
npm install --save @vx/legend
Examples
<Legend />
Components
APIs
#<Linear />
@vx/scale
or d3-scale
object used to generate the legend items.
((labels: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }[]) => ReactNode) | undefined
optional Optional render function override.
Classname to be applied to legend container.
"inherit" | "initial" | "revert" | "unset" | "column" | "column-reverse" | "row" | "row-reverse" | undefined
optional Flex direction of the legend itself.
Legend domain.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => string | number | undefined) | undefined
optional Legend item fill accessor function.
"inherit" | "initial" | "revert" | "unset" | "column" | "column-reverse" | "row" | "row-reverse" | undefined
optional Flex direction of legend items.
Margin of legend items.
Flex-box alignment of legend item labels.
Flex-box flex of legend item labels.
Given a legend item and its index, returns an item label.
Margin of legend item labels.
Given the legend scale and labelFormatter, returns a label with datum, index, value, and label.
Additional props to be set on LegendLabel.
"circle" | "rect" | "line" | FC<RenderShapeProvidedProps<Parameters<Scale>[0], ReturnType<Scale>>> | ComponentClass<...> | undefined
optional Legend shape string preset or Element or Component.
Height of the legend shape.
Margin of the legend shape.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => CSSProperties) | undefined
optional Styles applied to legend shapes.
Width of the legend shape.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => string | number | undefined) | undefined
optional Legend item size accessor function.
Default 5
Styles to be applied to the legend container.
#<Ordinal />
@vx/scale
or d3-scale
object used to generate the legend items.
((labels: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }[]) => ReactNode) | undefined
optional Optional render function override.
Classname to be applied to legend container.
"inherit" | "initial" | "revert" | "unset" | "column" | "column-reverse" | "row" | "row-reverse" | undefined
optional Flex direction of the legend itself.
Legend domain.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => string | number | undefined) | undefined
optional Legend item fill accessor function.
"inherit" | "initial" | "revert" | "unset" | "column" | "column-reverse" | "row" | "row-reverse" | undefined
optional Flex direction of legend items.
Margin of legend items.
Flex-box alignment of legend item labels.
Flex-box flex of legend item labels.
Given a legend item and its index, returns an item label.
Margin of legend item labels.
Given the legend scale and labelFormatter, returns a label with datum, index, value, and label.
Additional props to be set on LegendLabel.
"circle" | "rect" | "line" | FC<RenderShapeProvidedProps<Parameters<Scale>[0], ReturnType<Scale>>> | ComponentClass<...> | undefined
optional Legend shape string preset or Element or Component.
Height of the legend shape.
Margin of the legend shape.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => CSSProperties) | undefined
optional Styles applied to legend shapes.
Width of the legend shape.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => string | number | undefined) | undefined
optional Legend item size accessor function.
Styles to be applied to the legend container.
#<Quantile />
@vx/scale
or d3-scale
object used to generate the legend items.
((labels: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }[]) => ReactNode) | undefined
optional Optional render function override.
Classname to be applied to legend container.
"inherit" | "initial" | "revert" | "unset" | "column" | "column-reverse" | "row" | "row-reverse" | undefined
optional Flex direction of the legend itself.
Legend domain.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => string | number | undefined) | undefined
optional Legend item fill accessor function.
"inherit" | "initial" | "revert" | "unset" | "column" | "column-reverse" | "row" | "row-reverse" | undefined
optional Flex direction of legend items.
Margin of legend items.
Flex-box alignment of legend item labels.
Default -
Flex-box flex of legend item labels.
Given a legend item and its index, returns an item label.
Margin of legend item labels.
Given the legend scale and labelFormatter, returns a label with datum, index, value, and label.
Additional props to be set on LegendLabel.
"circle" | "rect" | "line" | FC<RenderShapeProvidedProps<Parameters<Scale>[0], ReturnType<Scale>>> | ComponentClass<...> | undefined
optional Legend shape string preset or Element or Component.
Height of the legend shape.
Margin of the legend shape.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => CSSProperties) | undefined
optional Styles applied to legend shapes.
Width of the legend shape.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => string | number | undefined) | undefined
optional Legend item size accessor function.
Styles to be applied to the legend container.
#<Size />
@vx/scale
or d3-scale
object used to generate the legend items.
((labels: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }[]) => ReactNode) | undefined
optional Optional render function override.
Classname to be applied to legend container.
"inherit" | "initial" | "revert" | "unset" | "column" | "column-reverse" | "row" | "row-reverse" | undefined
optional Flex direction of the legend itself.
Legend domain.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => string | number | undefined) | undefined
optional Legend item fill accessor function.
"inherit" | "initial" | "revert" | "unset" | "column" | "column-reverse" | "row" | "row-reverse" | undefined
optional Flex direction of legend items.
Margin of legend items.
Flex-box alignment of legend item labels.
Flex-box flex of legend item labels.
Given a legend item and its index, returns an item label.
Margin of legend item labels.
Given the legend scale and labelFormatter, returns a label with datum, index, value, and label.
Additional props to be set on LegendLabel.
"circle" | "rect" | "line" | FC<RenderShapeProvidedProps<Parameters<Scale>[0], ReturnType<Scale>>> | ComponentClass<...> | undefined
optional Legend shape string preset or Element or Component.
Height of the legend shape.
Margin of the legend shape.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => CSSProperties) | undefined
optional Styles applied to legend shapes.
Width of the legend shape.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => string | number | undefined) | undefined
optional Legend item size accessor function.
Default 5
Styles to be applied to the legend container.
#<Threshold />
@vx/scale
or d3-scale
object used to generate the legend items.
((labels: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }[]) => ReactNode) | undefined
optional Optional render function override.
Classname to be applied to legend container.
"inherit" | "initial" | "revert" | "unset" | "column" | "column-reverse" | "row" | "row-reverse" | undefined
optional Flex direction of the legend itself.
Legend domain.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => string | number | undefined) | undefined
optional Legend item fill accessor function.
"inherit" | "initial" | "revert" | "unset" | "column" | "column-reverse" | "row" | "row-reverse" | undefined
optional Flex direction of legend items.
Margin of legend items.
Flex-box alignment of legend item labels.
Default to
Flex-box flex of legend item labels.
Given a legend item and its index, returns an item label.
Default Less than
Margin of legend item labels.
Given the legend scale and labelFormatter, returns a label with datum, index, value, and label.
Default More than
Additional props to be set on LegendLabel.
"circle" | "rect" | "line" | FC<RenderShapeProvidedProps<Parameters<Scale>[0], ReturnType<Scale>>> | ComponentClass<...> | undefined
optional Legend shape string preset or Element or Component.
Height of the legend shape.
Margin of the legend shape.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => CSSProperties) | undefined
optional Styles applied to legend shapes.
Width of the legend shape.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => string | number | undefined) | undefined
optional Legend item size accessor function.
Styles to be applied to the legend container.
#<Legend />
@vx/scale
or d3-scale
object used to generate the legend items.
((labels: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }[]) => ReactNode) | undefined
optional Optional render function override.
Classname to be applied to legend container.
"inherit" | "initial" | "revert" | "unset" | "column" | "column-reverse" | "row" | "row-reverse" | undefined
optional Flex direction of the legend itself.
Default column
Legend domain.
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => string | number | undefined) | undefined
optional Legend item fill accessor function.
"inherit" | "initial" | "revert" | "unset" | "column" | "column-reverse" | "row" | "row-reverse" | undefined
optional Flex direction of legend items.
Default row
Margin of legend items.
Default 0
Flex-box alignment of legend item labels.
Default left
Flex-box flex of legend item labels.
Default 1
Given a legend item and its index, returns an item label.
Margin of legend item labels.
Default 0 4px
Given the legend scale and labelFormatter, returns a label with datum, index, value, and label.
Additional props to be set on LegendLabel.
"circle" | "rect" | "line" | FC<RenderShapeProvidedProps<Parameters<Scale>[0], ReturnType<Scale>>> | ComponentClass<...> | undefined
optional Legend shape string preset or Element or Component.
Height of the legend shape.
Default 15
Margin of the legend shape.
Default 2px 4px 2px 0
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => CSSProperties) | undefined
optional Styles applied to legend shapes.
Width of the legend shape.
Default 15
((label: { datum: Parameters<Scale>[0]; index: number; text: string; value?: ReturnType<Scale> | undefined; }) => string | number | undefined) | undefined
optional Legend item size accessor function.
Styles to be applied to the legend container.