forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChartLineBasicRightLegend.tsx
More file actions
83 lines (80 loc) · 2.3 KB
/
ChartLineBasicRightLegend.tsx
File metadata and controls
83 lines (80 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { Chart, ChartAxis, ChartGroup, ChartLine, ChartVoronoiContainer } from '@patternfly/react-charts/victory';
interface PetData {
name?: string;
x?: string;
y?: number;
symbol?: { type: string };
}
export const ChartLineBasicRightLegend: React.FunctionComponent = () => {
const legendData: PetData[] = [
{ name: 'Cats' },
{ name: 'Dogs', symbol: { type: 'dash' } },
{ name: 'Birds' },
{ name: 'Mice' }
];
const data1: PetData[] = [
{ name: 'Cats', x: '2015', y: 1 },
{ name: 'Cats', x: '2016', y: 2 },
{ name: 'Cats', x: '2017', y: 5 },
{ name: 'Cats', x: '2018', y: 3 }
];
const data2: PetData[] = [
{ name: 'Dogs', x: '2015', y: 2 },
{ name: 'Dogs', x: '2016', y: 1 },
{ name: 'Dogs', x: '2017', y: 7 },
{ name: 'Dogs', x: '2018', y: 4 }
];
const data3: PetData[] = [
{ name: 'Birds', x: '2015', y: 3 },
{ name: 'Birds', x: '2016', y: 4 },
{ name: 'Birds', x: '2017', y: 9 },
{ name: 'Birds', x: '2018', y: 5 }
];
const data4: PetData[] = [
{ name: 'Mice', x: '2015', y: 3 },
{ name: 'Mice', x: '2016', y: 3 },
{ name: 'Mice', x: '2017', y: 8 },
{ name: 'Mice', x: '2018', y: 7 }
];
return (
<div style={{ height: '250px', width: '600px' }}>
<Chart
ariaDesc="Average number of pets"
ariaTitle="Line chart example"
containerComponent={
<ChartVoronoiContainer labels={({ datum }) => `${datum.name}: ${datum.y}`} constrainToVisibleArea />
}
legendData={legendData}
legendOrientation="vertical"
legendPosition="right"
height={250}
maxDomain={{ y: 10 }}
minDomain={{ y: 0 }}
name="chart1"
padding={{
bottom: 50,
left: 50,
right: 200, // Adjusted to accommodate legend
top: 50
}}
width={600}
>
<ChartAxis tickValues={[2, 3, 4]} />
<ChartAxis dependentAxis showGrid tickValues={[2, 5, 8]} />
<ChartGroup>
<ChartLine data={data1} />
<ChartLine
data={data2}
style={{
data: {
strokeDasharray: '3,3'
}
}}
/>
<ChartLine data={data3} />
<ChartLine data={data4} />
</ChartGroup>
</Chart>
</div>
);
};