import { Chart, ChartAxis, ChartGroup, ChartLine, ChartScatter, ChartThemeColor, ChartVoronoiContainer } from '@patternfly/react-charts/victory'; import { getResizeObserver } from '@patternfly/react-core'; import { useEffect, useRef, useState } from 'react'; export const ChartScatterLineChart: React.FunctionComponent = () => { const containerRef = useRef(null); const observer = useRef(() => {}); const [width, setWidth] = useState(0); const handleResize = () => { if (containerRef.current && containerRef.current.clientWidth) { setWidth(containerRef.current.clientWidth); } }; const series = [ { datapoints: [ { name: 'Cats', x: '2015', y: 1 }, { name: 'Cats', x: '2016', y: 2 }, { name: 'Cats', x: '2017', y: 5 }, { name: 'Cats', x: '2018', y: 3 } ], legendItem: { name: 'Cats' } }, { datapoints: [ { name: 'Dogs', x: '2015', y: 2 }, { name: 'Dogs', x: '2016', y: 1 }, { name: 'Dogs', x: '2017', y: 7 }, { name: 'Dogs', x: '2018', y: 4 } ], legendItem: { name: 'Dogs' }, style: { data: { strokeDasharray: '3,3' } } }, { datapoints: [ { name: 'Birds', x: '2015', y: 3 }, { name: 'Birds', x: '2016', y: 4 }, { name: 'Birds', x: '2017', y: 9 }, { name: 'Birds', x: '2018', y: 5 } ], legendItem: { name: 'Birds' } }, { datapoints: [ { name: 'Mice', x: '2015', y: 3 }, { name: 'Mice', x: '2016', y: 3 }, { name: 'Mice', x: '2017', y: 8 }, { name: 'Mice', x: '2018', y: 7 } ], legendItem: { name: 'Mice' } } ]; useEffect(() => { observer.current = getResizeObserver(containerRef.current, handleResize); handleResize(); return () => { observer.current(); }; }, []); return (