@@ -33,142 +33,21 @@ The examples below are based on the [Victory](https://formidable.com/open-source
3333
3434## Examples
3535### Basic with right aligned legend
36- ``` js
37- import { Chart , ChartAxis , ChartBar , ChartStack , ChartVoronoiContainer } from ' @patternfly/react-charts/victory' ;
38-
39- < div style= {{ height: ' 250px' , width: ' 600px' }}>
40- < Chart
41- ariaDesc= " Average number of pets"
42- ariaTitle= " Stack chart example"
43- containerComponent= {< ChartVoronoiContainer labels= {({ datum }) => ` ${ datum .name } : ${ datum .y } ` } constrainToVisibleArea / > }
44- domainPadding= {{ x: [30 , 25 ] }}
45- legendData= {[{ name: ' Cats' }, { name: ' Dogs' }, { name: ' Birds' }, { name: ' Mice' }]}
46- legendOrientation= " vertical"
47- legendPosition= " right"
48- height= {250 }
49- name= " chart1"
50- padding= {{
51- bottom: 50 ,
52- left: 50 ,
53- right: 200 , // Adjusted to accommodate legend
54- top: 50
55- }}
56- width= {600 }
57- >
58- < ChartAxis / >
59- < ChartAxis dependentAxis showGrid / >
60- < ChartStack>
61- < ChartBar data= {[{ name: ' Cats' , x: ' 2015' , y: 1 }, { name: ' Cats' , x: ' 2016' , y: 2 }, { name: ' Cats' , x: ' 2017' , y: 5 }, { name: ' Cats' , x: ' 2018' , y: 3 }]} / >
62- < ChartBar data= {[{ name: ' Dogs' , x: ' 2015' , y: 2 }, { name: ' Dogs' , x: ' 2016' , y: 1 }, { name: ' Dogs' , x: ' 2017' , y: 7 }, { name: ' Dogs' , x: ' 2018' , y: 4 }]} / >
63- < ChartBar data= {[{ name: ' Birds' , x: ' 2015' , y: 4 }, { name: ' Birds' , x: ' 2016' , y: 4 }, { name: ' Birds' , x: ' 2017' , y: 9 }, { name: ' Birds' , x: ' 2018' , y: 7 }]} / >
64- < ChartBar data= {[{ name: ' Mice' , x: ' 2015' , y: 3 }, { name: ' Mice' , x: ' 2016' , y: 3 }, { name: ' Mice' , x: ' 2017' , y: 8 }, { name: ' Mice' , x: ' 2018' , y: 5 }]} / >
65- < / ChartStack>
66- < / Chart>
67- < / div>
36+ ``` ts file = "ChartStackBasicRightLegend.tsx"
37+
6838```
6939
7040### Horizontal with bottom aligned legend
71- ``` js
72- import { Chart , ChartAxis , ChartBar , ChartStack , ChartThemeColor , ChartVoronoiContainer } from ' @patternfly/react-charts/victory' ;
73-
74- < div style= {{ height: ' 275px' , width: ' 450px' }}>
75- < Chart
76- ariaDesc= " Average number of pets"
77- ariaTitle= " Stack chart example"
78- containerComponent= {< ChartVoronoiContainer labels= {({ datum }) => ` ${ datum .name } : ${ datum .y } ` } constrainToVisibleArea / > }
79- domainPadding= {{ x: [30 , 25 ] }}
80- legendData= {[{ name: ' Cats' }, { name: ' Dogs' }, { name: ' Birds' }, { name: ' Mice' }]}
81- legendPosition= " bottom"
82- height= {275 }
83- name= " chart2"
84- padding= {{
85- bottom: 75 , // Adjusted to accommodate legend
86- left: 50 ,
87- right: 50 ,
88- top: 50
89- }}
90- themeColor= {ChartThemeColor .yellow }
91- width= {450 }
92- >
93- < ChartAxis / >
94- < ChartAxis dependentAxis showGrid / >
95- < ChartStack>
96- < ChartBar data= {[{ name: ' Cats' , x: ' 2015' , y: 1 }, { name: ' Cats' , x: ' 2016' , y: 2 }, { name: ' Cats' , x: ' 2017' , y: 5 }, { name: ' Cats' , x: ' 2018' , y: 3 }]} / >
97- < ChartBar data= {[{ name: ' Dogs' , x: ' 2015' , y: 2 }, { name: ' Dogs' , x: ' 2016' , y: 1 }, { name: ' Dogs' , x: ' 2017' , y: 7 }, { name: ' Dogs' , x: ' 2018' , y: 4 }]} / >
98- < ChartBar data= {[{ name: ' Birds' , x: ' 2015' , y: 4 }, { name: ' Birds' , x: ' 2016' , y: 4 }, { name: ' Birds' , x: ' 2017' , y: 9 }, { name: ' Birds' , x: ' 2018' , y: 7 }]} / >
99- < ChartBar data= {[{ name: ' Mice' , x: ' 2015' , y: 3 }, { name: ' Mice' , x: ' 2016' , y: 3 }, { name: ' Mice' , x: ' 2017' , y: 8 }, { name: ' Mice' , x: ' 2018' , y: 5 }]} / >
100- < / ChartStack>
101- < / Chart>
102- < / div>
41+ ``` ts file = "ChartStackHorizontalBottomLegend.tsx"
42+
10343```
10444
10545### Multi-color (ordered) horizontal with bottom aligned legend
10646
10747This demonstrates an alternate way of applying tooltips using data labels.
10848
109- ``` js
110- import { Chart , ChartBar , ChartAxis , ChartStack , ChartThemeColor , ChartTooltip } from ' @patternfly/react-charts/victory' ;
111-
112- < div style= {{ height: ' 275px' , width: ' 450px' }}>
113- < Chart
114- ariaDesc= " Average number of pets"
115- ariaTitle= " Stack chart example"
116- domainPadding= {{ x: [30 , 25 ] }}
117- legendData= {[{ name: ' Cats' }, { name: ' Dogs' }, { name: ' Birds' }, { name: ' Mice' }]}
118- legendPosition= " bottom-left"
119- height= {275 }
120- name= " chart3"
121- padding= {{
122- bottom: 75 , // Adjusted to accommodate legend
123- left: 50 ,
124- right: 50 ,
125- top: 50
126- }}
127- themeColor= {ChartThemeColor .multiOrdered }
128- width= {450 }
129- >
130- < ChartAxis / >
131- < ChartAxis dependentAxis showGrid / >
132- < ChartStack horizontal>
133- < ChartBar
134- data= {[
135- { name: ' Cats' , x: ' 2015' , y: 1 , label: ' Cats: 1' },
136- { name: ' Cats' , x: ' 2016' , y: 2 , label: ' Cats: 2' },
137- { name: ' Cats' , x: ' 2017' , y: 5 , label: ' Cats: 5' },
138- { name: ' Cats' , x: ' 2018' , y: 3 , label: ' Cats: 3' }
139- ]}
140- labelComponent= {< ChartTooltip constrainToVisibleArea / > }
141- / >
142- < ChartBar
143- data= {[
144- { name: ' Dogs' , x: ' 2015' , y: 2 , label: ' Dogs: 2' },
145- { name: ' Dogs' , x: ' 2016' , y: 1 , label: ' Dogs: 1' },
146- { name: ' Dogs' , x: ' 2017' , y: 7 , label: ' Dogs: 7' },
147- { name: ' Dogs' , x: ' 2018' , y: 4 , label: ' Dogs: 4' }
148- ]}
149- labelComponent= {< ChartTooltip constrainToVisibleArea / > }
150- / >
151- < ChartBar
152- data= {[
153- { name: ' Birds' , x: ' 2015' , y: 4 , label: ' Birds: 4' },
154- { name: ' Birds' , x: ' 2016' , y: 4 , label: ' Birds: 4' },
155- { name: ' Birds' , x: ' 2017' , y: 9 , label: ' Birds: 9' },
156- { name: ' Birds' , x: ' 2018' , y: 7 , label: ' Birds: 7' }
157- ]}
158- labelComponent= {< ChartTooltip constrainToVisibleArea / > }
159- / >
160- < ChartBar
161- data= {[
162- { name: ' Mice' , x: ' 2015' , y: 3 , label: ' Mice: 3' },
163- { name: ' Mice' , x: ' 2016' , y: 3 , label: ' Mice: 3' },
164- { name: ' Mice' , x: ' 2017' , y: 8 , label: ' Mice: 8' },
165- { name: ' Mice' , x: ' 2018' , y: 5 , label: ' Mice: 5' }
166- ]}
167- labelComponent= {< ChartTooltip constrainToVisibleArea / > }
168- / >
169- < / ChartStack>
170- < / Chart>
171- < / div>
49+ ``` ts file = "ChartStackMultiColorOrdered.tsx"
50+
17251```
17352
17453### Monthly data with responsive container
0 commit comments