Skip to content

Commit 6d9a391

Browse files
committed
added example - Labels with bottom aligned legend
1 parent 4e6b2ad commit 6d9a391

File tree

2 files changed

+52
-39
lines changed

2 files changed

+52
-39
lines changed

packages/react-charts/src/victory/components/ChartBoxPlot/examples/ChartBoxPlot.md

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,46 +32,8 @@ The examples below are based on the [Victory](https://formidable.com/open-source
3232

3333
This demonstrates how to display labels.
3434

35-
```js
36-
import { Chart, ChartAxis, ChartBoxPlot, ChartThemeColor } from '@patternfly/react-charts/victory';
35+
```ts file= "ChartBoxPlotLabels.tsx"
3736

38-
<div style={{ height: '300px', width: '600px' }}>
39-
<Chart
40-
ariaDesc="Average number of pets"
41-
ariaTitle="Bar chart example"
42-
domain={{y: [0, 12]}}
43-
domainPadding={{ x: [30, 25] }}
44-
legendData={[{ name: 'Cats' }]}
45-
legendPosition="bottom"
46-
height={300}
47-
name="chart2"
48-
padding={{
49-
bottom: 75, // Adjusted to accommodate legend
50-
left: 50,
51-
right: 50,
52-
top: 50
53-
}}
54-
themeColor={ChartThemeColor.yellow}
55-
width={600}
56-
>
57-
<ChartAxis />
58-
<ChartAxis dependentAxis showGrid />
59-
<ChartBoxPlot
60-
data={[
61-
{ name: 'Cats', x: '2015', y: [1, 2, 3, 5] },
62-
{ name: 'Cats', x: '2016', y: [3, 2, 8, 10] },
63-
{ name: 'Cats', x: '2017', y: [2, 8, 6, 5] },
64-
{ name: 'Cats', x: '2018', y: [1, 3, 2, 9] }
65-
]}
66-
labelOrientation={{
67-
min: "right",
68-
max: "right",
69-
}}
70-
maxLabels
71-
minLabels
72-
/>
73-
</Chart>
74-
</div>
7537
```
7638

7739
### Embedded legend
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Chart, ChartAxis, ChartBoxPlot, ChartThemeColor } from '@patternfly/react-charts/victory';
2+
3+
interface PetData {
4+
name: string;
5+
x: string;
6+
y: number[];
7+
}
8+
9+
export const ChartBoxPlotLabels: React.FunctionComponent = () => {
10+
const catsData: PetData[] = [
11+
{ name: 'Cats', x: '2015', y: [1, 2, 3, 5] },
12+
{ name: 'Cats', x: '2016', y: [3, 2, 8, 10] },
13+
{ name: 'Cats', x: '2017', y: [2, 8, 6, 5] },
14+
{ name: 'Cats', x: '2018', y: [1, 3, 2, 9] }
15+
];
16+
const legendData = [{ name: 'Cats' }];
17+
return (
18+
<div style={{ height: '300px', width: '600px' }}>
19+
<Chart
20+
ariaDesc="Average number of pets"
21+
ariaTitle="Bar chart example"
22+
domain={{ y: [0, 12] }}
23+
domainPadding={{ x: [30, 25] }}
24+
legendData={legendData}
25+
legendPosition="bottom"
26+
height={300}
27+
name="chart2"
28+
padding={{
29+
bottom: 75, // Adjusted to accommodate legend
30+
left: 50,
31+
right: 50,
32+
top: 50
33+
}}
34+
themeColor={ChartThemeColor.yellow}
35+
width={600}
36+
>
37+
<ChartAxis />
38+
<ChartAxis dependentAxis showGrid />
39+
<ChartBoxPlot
40+
data={catsData}
41+
labelOrientation={{
42+
min: 'right',
43+
max: 'right'
44+
}}
45+
maxLabels
46+
minLabels
47+
/>
48+
</Chart>
49+
</div>
50+
);
51+
};

0 commit comments

Comments
 (0)