| id | Legends | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| section | components | ||||||||||||||
| subsection | charts | ||||||||||||||
| propComponents |
|
||||||||||||||
| hideDarkMode | true |
import { cloneElement, useEffect, useRef, useState } from 'react'; import { Chart, ChartArea, ChartAxis, ChartBar, ChartBullet, ChartContainer, ChartDonut, ChartGroup, ChartLabel, ChartLegend, ChartLegendTooltip, ChartLine, ChartPie, ChartScatter, ChartThemeColor, ChartVoronoiContainer, createContainer, getInteractiveLegendEvents, getInteractiveLegendItemStyles } from '@patternfly/react-charts/victory'; import { getResizeObserver } from '@patternfly/react-core'; import chart_color_black_500 from '@patternfly/react-tokens/dist/esm/chart_color_black_500'; import '@patternfly/patternfly/patternfly-charts.css';
Note: PatternFly React charts live in its own package at @patternfly/react-charts!
The examples below are based on the Victory chart library, along with additional functionality, custom components, and theming for PatternFly. This provides a collection of React based components you can use to build PatternFly patterns with consistent markup, styling, and behavior.
This demonstrates a responsive legend which wraps when items are wider than its container.
This demonstrates a standalone legend vs. using the legendData property.
This demonstrates how to add an interactive legend using events such as onMouseOver, onMouseOut, and onClick.
This demonstrates how to add an interactive legend to a pie chart using events such as onMouseOver, onMouseOut, and onClick.
This demonstrates an approach for applying tooltips to a legend using a custom label component. These tooltips are keyboard navigable.
This demonstrates an approach for applying links to a legend using a custom label component. These links are keyboard navigable.
This demonstrates an approach for applying a different legend layout and styles using a custom label component.
- See Victory's FAQ
ChartLegendmay be used as a standalone component, instead of usinglegendData
Currently, the generated documentation below is not able to resolve type definitions from Victory imports. For the components used in the examples above, Victory pass-thru props are also documented here:
- For
Chartprops, see VictoryChart - For
ChartAreaprops, see VictoryArea - For
ChartAxisprops, see VictoryAxis - For
ChartBarprops, see VictoryBar - For
ChartBulletprops, see VictoryBar - For
ChartDonutprops, see VictoryPie - For
ChartGroupprops, see VictoryGroup - For
ChartLabelprops, see VictoryLabel - For
ChartLegendprops, see VictoryLegend - For
ChartLineprops, see VictoryLine - For
ChartPieprops, see VictoryPie - For
ChartScatterprops, see VictoryScatter - For
ChartVoronoiContainerprops, see VictoryVoronoiContainer