Skip to content

Commit 0093d9c

Browse files
committed
converted example - teal with bottom aligned legend and axis label
1 parent 57e12cc commit 0093d9c

File tree

3 files changed

+92
-80
lines changed

3 files changed

+92
-80
lines changed

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

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

3232
This demonstrates how to combine cursor and voronoi containers to display tooltips along with a cursor.
3333

34-
```js
35-
import { Chart, ChartArea, ChartAxis, ChartGroup, ChartThemeColor, ChartLegendTooltip, createContainer } from '@patternfly/react-charts/victory';
36-
// import '@patternfly/patternfly/patternfly-charts.css'; // Required for mix-blend-mode CSS property
34+
```ts file = "ChartAreaTealBottomAlignedLegend.tsx"
3735

38-
class BottomAlignedLegend extends React.Component {
39-
render() {
40-
// Note: Container order is important
41-
const CursorVoronoiContainer = createContainer("voronoi", "cursor");
42-
const legendData = [{ childName: 'cats', name: 'Cats' }, { childName: 'dogs', name: 'Dogs' }, { childName: 'birds', name: 'Birds' }];
43-
44-
return (
45-
<div style={{ height: '250px', width: '650px' }}>
46-
<Chart
47-
ariaDesc="Average number of pets"
48-
ariaTitle="Area chart example"
49-
containerComponent={
50-
<CursorVoronoiContainer
51-
cursorDimension="x"
52-
labels={({ datum }) => `${datum.y}`}
53-
labelComponent={<ChartLegendTooltip legendData={legendData} title={(datum) => datum.x}/>}
54-
mouseFollowTooltips
55-
voronoiDimension="x"
56-
voronoiPadding={50}
57-
/>
58-
}
59-
legendData={legendData}
60-
legendPosition="bottom"
61-
height={250}
62-
name="chart2"
63-
padding={{
64-
bottom: 100, // Adjusted to accommodate legend
65-
left: 50,
66-
right: 50,
67-
top: 50,
68-
}}
69-
maxDomain={{y: 9}}
70-
themeColor={ChartThemeColor.teal}
71-
width={650}
72-
>
73-
<ChartAxis label="Years" fixAxisLabelHeight />
74-
<ChartAxis dependentAxis showGrid/>
75-
<ChartGroup>
76-
<ChartArea
77-
data={[
78-
{ x: '2015', y: 3 },
79-
{ x: '2016', y: 4 },
80-
{ x: '2017', y: 8 },
81-
{ x: '2018', y: 6 }
82-
]}
83-
interpolation="monotoneX"
84-
name="cats"
85-
/>
86-
<ChartArea
87-
data={[
88-
{ x: '2015', y: 2 },
89-
{ x: '2016', y: 3 },
90-
{ x: '2017', y: 4 },
91-
{ x: '2018', y: 5 },
92-
{ x: '2019', y: 6 }
93-
]}
94-
interpolation="monotoneX"
95-
name="dogs"
96-
/>
97-
<ChartArea
98-
data={[
99-
{ x: '2015', y: 1 },
100-
{ x: '2016', y: 2 },
101-
{ x: '2017', y: 3 },
102-
{ x: '2018', y: 2 },
103-
{ x: '2019', y: 4 }
104-
]}
105-
interpolation="monotoneX"
106-
name="birds"
107-
/>
108-
</ChartGroup>
109-
</Chart>
110-
</div>
111-
);
112-
}
113-
}
11436
```
11537

11638
### Multi-color (unordered) bottom-left aligned legend and responsive container

packages/react-charts/src/victory/components/ChartArea/examples/ChartAreaRightAlignedLegend.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export const ChartAreaRightAlignedLegend: React.FunctionComponent = () => {
3131
{ name: 'Birds', x: '2019', y: 4 }
3232
];
3333

34+
const legendData = [{ name: 'Cats' }, { name: 'Dogs' }, { name: 'Birds' }];
35+
3436
return (
3537
<div style={{ height: '200px', width: '800px' }}>
3638
<Chart
@@ -39,7 +41,7 @@ export const ChartAreaRightAlignedLegend: React.FunctionComponent = () => {
3941
containerComponent={
4042
<ChartVoronoiContainer labels={({ datum }) => `${datum.name}: ${datum.y}`} constrainToVisibleArea />
4143
}
42-
legendData={[{ name: 'Cats' }, { name: 'Dogs' }, { name: 'Birds' }]}
44+
legendData={legendData}
4345
legendOrientation="vertical"
4446
legendPosition="right"
4547
height={200}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import {
2+
Chart,
3+
ChartArea,
4+
ChartAxis,
5+
ChartGroup,
6+
ChartThemeColor,
7+
ChartLegendTooltip,
8+
createContainer
9+
} from '@patternfly/react-charts/victory';
10+
// import '@patternfly/patternfly/patternfly-charts.css'; // Required for mix-blend-mode CSS property
11+
12+
interface PetData {
13+
x: string;
14+
y: number;
15+
}
16+
17+
export const BottomAlignedLegend: React.FunctionComponent = () => {
18+
// Note: Container order is important
19+
const CursorVoronoiContainer = createContainer('voronoi', 'cursor');
20+
const legendData = [
21+
{ childName: 'cats', name: 'Cats' },
22+
{ childName: 'dogs', name: 'Dogs' },
23+
{ childName: 'birds', name: 'Birds' }
24+
];
25+
26+
const catsData: PetData[] = [
27+
{ x: '2015', y: 3 },
28+
{ x: '2016', y: 4 },
29+
{ x: '2017', y: 8 },
30+
{ x: '2018', y: 6 }
31+
];
32+
33+
const dogsData: PetData[] = [
34+
{ x: '2015', y: 2 },
35+
{ x: '2016', y: 3 },
36+
{ x: '2017', y: 4 },
37+
{ x: '2018', y: 5 },
38+
{ x: '2019', y: 6 }
39+
];
40+
41+
const birdsData: PetData[] = [
42+
{ x: '2015', y: 1 },
43+
{ x: '2016', y: 2 },
44+
{ x: '2017', y: 3 },
45+
{ x: '2018', y: 2 },
46+
{ x: '2019', y: 4 }
47+
];
48+
49+
return (
50+
<div style={{ height: '250px', width: '650px' }}>
51+
<Chart
52+
ariaDesc="Average number of pets"
53+
ariaTitle="Area chart example"
54+
containerComponent={
55+
<CursorVoronoiContainer
56+
cursorDimension="x"
57+
labels={({ datum }) => `${datum.y}`}
58+
labelComponent={<ChartLegendTooltip legendData={legendData} title={(datum) => datum.x} />}
59+
mouseFollowTooltips
60+
voronoiDimension="x"
61+
voronoiPadding={50}
62+
/>
63+
}
64+
legendData={legendData}
65+
legendPosition="bottom"
66+
height={250}
67+
name="chart2"
68+
padding={{
69+
bottom: 100, // Adjusted to accommodate legend
70+
left: 50,
71+
right: 50,
72+
top: 50
73+
}}
74+
maxDomain={{ y: 9 }}
75+
themeColor={ChartThemeColor.teal}
76+
width={650}
77+
>
78+
<ChartAxis label="Years" fixAxisLabelHeight />
79+
<ChartAxis dependentAxis showGrid />
80+
<ChartGroup>
81+
<ChartArea data={catsData} interpolation="monotoneX" name="cats" />
82+
<ChartArea data={dogsData} interpolation="monotoneX" name="dogs" />
83+
<ChartArea data={birdsData} interpolation="monotoneX" name="birds" />
84+
</ChartGroup>
85+
</Chart>
86+
</div>
87+
);
88+
};

0 commit comments

Comments
 (0)