import { ChartLabel, ChartLegend, ChartPie, ChartThemeColor } from '@patternfly/react-charts/victory'; import { Tooltip } from '@patternfly/react-core'; import { useRef } from 'react'; interface PetData { x: string; y: number; } export const ChartTooltipLegend: React.FunctionComponent = () => { // Custom legend label component // Note: Tooltip wraps children with a div tag, so we add a reference to ChartLabel instead const LegendLabel = ({ datum, ...rest }) => { const ref = useRef(null); return ( ); }; // Custom legend component const getLegend = (legendData) => } />; const data: PetData[] = [ { x: 'Cats', y: 35 }, { x: 'Dogs', y: 55 }, { x: 'Birds', y: 10 } ]; return (
`${datum.x}: ${datum.y}`} legendComponent={getLegend([{ name: 'Cats: 35' }, { name: 'Dogs: 55' }, { name: 'Birds: 10' }])} legendPosition="bottom" name="chart7" padding={{ bottom: 65, left: 20, right: 20, top: 20 }} themeColor={ChartThemeColor.multiOrdered} width={300} />
); };