|
| 1 | +import { Chart, ChartArea, ChartAxis, ChartGroup, ChartVoronoiContainer } from '@patternfly/react-charts/victory'; |
| 2 | + |
| 3 | +interface PetData { |
| 4 | + name?: string; |
| 5 | + x?: string; |
| 6 | + y?: number; |
| 7 | +} |
| 8 | + |
| 9 | +export const ChartTooltipVoronoi: React.FunctionComponent = () => { |
| 10 | + const legendData: PetData[] = [{ name: 'Cats' }, { name: 'Dogs' }, { name: 'Birds' }]; |
| 11 | + |
| 12 | + const data1: PetData[] = [ |
| 13 | + { name: 'Cats', x: '2015', y: 3 }, |
| 14 | + { name: 'Cats', x: '2016', y: 4 }, |
| 15 | + { name: 'Cats', x: '2017', y: 8 }, |
| 16 | + { name: 'Cats', x: '2018', y: 6 } |
| 17 | + ]; |
| 18 | + |
| 19 | + const data2: PetData[] = [ |
| 20 | + { name: 'Dogs', x: '2015', y: 2 }, |
| 21 | + { name: 'Dogs', x: '2016', y: 3 }, |
| 22 | + { name: 'Dogs', x: '2017', y: 4 }, |
| 23 | + { name: 'Dogs', x: '2018', y: 5 }, |
| 24 | + { name: 'Dogs', x: '2019', y: 6 } |
| 25 | + ]; |
| 26 | + |
| 27 | + const data3: PetData[] = [ |
| 28 | + { name: 'Birds', x: '2015', y: 1 }, |
| 29 | + { name: 'Birds', x: '2016', y: 2 }, |
| 30 | + { name: 'Birds', x: '2017', y: 3 }, |
| 31 | + { name: 'Birds', x: '2018', y: 2 }, |
| 32 | + { name: 'Birds', x: '2019', y: 4 } |
| 33 | + ]; |
| 34 | + |
| 35 | + return ( |
| 36 | + <div style={{ height: '200px', width: '800px' }}> |
| 37 | + <Chart |
| 38 | + ariaDesc="Average number of pets - possibly more information to summarize the data in the chart." |
| 39 | + ariaTitle="Area chart example chart title" |
| 40 | + containerComponent={ |
| 41 | + <ChartVoronoiContainer labels={({ datum }) => `${datum.name}: ${datum.y}`} constrainToVisibleArea /> |
| 42 | + } |
| 43 | + legendData={legendData} |
| 44 | + legendOrientation="vertical" |
| 45 | + legendPosition="right" |
| 46 | + height={200} |
| 47 | + maxDomain={{ y: 9 }} |
| 48 | + name="chart1" |
| 49 | + padding={{ |
| 50 | + bottom: 50, |
| 51 | + left: 50, |
| 52 | + right: 200, // Adjusted to accommodate legend |
| 53 | + top: 50 |
| 54 | + }} |
| 55 | + width={800} |
| 56 | + > |
| 57 | + <ChartAxis /> |
| 58 | + <ChartAxis dependentAxis showGrid /> |
| 59 | + <ChartGroup> |
| 60 | + <ChartArea data={data1} interpolation="monotoneX" /> |
| 61 | + <ChartArea data={data2} interpolation="monotoneX" /> |
| 62 | + <ChartArea data={data3} interpolation="monotoneX" /> |
| 63 | + </ChartGroup> |
| 64 | + </Chart> |
| 65 | + </div> |
| 66 | + ); |
| 67 | +}; |
0 commit comments