Skip to content

Commit c78226a

Browse files
committed
chore(chart bar): convert to typescript
1 parent c1321c8 commit c78226a

File tree

2 files changed

+74
-62
lines changed

2 files changed

+74
-62
lines changed

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

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

2222
### Basic with right aligned legend
2323

24-
```js
25-
import { Chart, ChartAxis, ChartBar, ChartGroup, ChartVoronoiContainer } from '@patternfly/react-charts/victory';
24+
```ts file = "ChartBarBasic.tsx"
2625

27-
<div style={{ height: '250px', width: '600px' }}>
28-
<Chart
29-
ariaDesc="Average number of pets"
30-
ariaTitle="Bar chart example"
31-
containerComponent={
32-
<ChartVoronoiContainer labels={({ datum }) => `${datum.name}: ${datum.y}`} constrainToVisibleArea />
33-
}
34-
domain={{ y: [0, 9] }}
35-
domainPadding={{ x: [30, 25] }}
36-
legendData={[{ name: 'Cats' }, { name: 'Dogs' }, { name: 'Birds' }, { name: 'Mice' }]}
37-
legendOrientation="vertical"
38-
legendPosition="right"
39-
height={250}
40-
name="chart1"
41-
padding={{
42-
bottom: 50,
43-
left: 50,
44-
right: 200, // Adjusted to accommodate legend
45-
top: 50
46-
}}
47-
width={600}
48-
>
49-
<ChartAxis />
50-
<ChartAxis dependentAxis showGrid />
51-
<ChartGroup offset={11}>
52-
<ChartBar
53-
data={[
54-
{ name: 'Cats', x: '2015', y: 1 },
55-
{ name: 'Cats', x: '2016', y: 2 },
56-
{ name: 'Cats', x: '2017', y: 5 },
57-
{ name: 'Cats', x: '2018', y: 3 }
58-
]}
59-
/>
60-
<ChartBar
61-
data={[
62-
{ name: 'Dogs', x: '2015', y: 2 },
63-
{ name: 'Dogs', x: '2016', y: 1 },
64-
{ name: 'Dogs', x: '2017', y: 7 },
65-
{ name: 'Dogs', x: '2018', y: 4 }
66-
]}
67-
/>
68-
<ChartBar
69-
data={[
70-
{ name: 'Birds', x: '2015', y: 4 },
71-
{ name: 'Birds', x: '2016', y: 4 },
72-
{ name: 'Birds', x: '2017', y: 9 },
73-
{ name: 'Birds', x: '2018', y: 7 }
74-
]}
75-
/>
76-
<ChartBar
77-
data={[
78-
{ name: 'Mice', x: '2015', y: 3 },
79-
{ name: 'Mice', x: '2016', y: 3 },
80-
{ name: 'Mice', x: '2017', y: 8 },
81-
{ name: 'Mice', x: '2018', y: 5 }
82-
]}
83-
/>
84-
</ChartGroup>
85-
</Chart>
86-
</div>;
8726
```
8827

8928
### Purple with bottom aligned legend
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { Chart, ChartAxis, ChartBar, 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 ChartBarBasic: React.FunctionComponent = () => {
10+
const catsData: PetData[] = [
11+
{ name: 'Cats', x: '2015', y: 1 },
12+
{ name: 'Cats', x: '2016', y: 2 },
13+
{ name: 'Cats', x: '2017', y: 5 },
14+
{ name: 'Cats', x: '2018', y: 3 }
15+
];
16+
const dogsData: PetData[] = [
17+
{ name: 'Dogs', x: '2015', y: 2 },
18+
{ name: 'Dogs', x: '2016', y: 1 },
19+
{ name: 'Dogs', x: '2017', y: 7 },
20+
{ name: 'Dogs', x: '2018', y: 4 }
21+
];
22+
23+
const birdsData: PetData[] = [
24+
{ name: 'Birds', x: '2015', y: 4 },
25+
{ name: 'Birds', x: '2016', y: 4 },
26+
{ name: 'Birds', x: '2017', y: 9 },
27+
{ name: 'Birds', x: '2018', y: 7 }
28+
];
29+
30+
const miceData: PetData[] = [
31+
{ name: 'Mice', x: '2015', y: 3 },
32+
{ name: 'Mice', x: '2016', y: 3 },
33+
{ name: 'Mice', x: '2017', y: 8 },
34+
{ name: 'Mice', x: '2018', y: 5 }
35+
];
36+
37+
const legendData = [{ name: 'Cats' }, { name: 'Dogs' }, { name: 'Birds' }, { name: 'Mice' }];
38+
39+
return (
40+
<div style={{ height: '250px', width: '600px' }}>
41+
<Chart
42+
ariaDesc="Average number of pets"
43+
ariaTitle="Bar chart example"
44+
containerComponent={
45+
<ChartVoronoiContainer labels={({ datum }) => `${datum.name}: ${datum.y}`} constrainToVisibleArea />
46+
}
47+
domain={{ y: [0, 9] }}
48+
domainPadding={{ x: [30, 25] }}
49+
legendData={legendData}
50+
legendOrientation="vertical"
51+
legendPosition="right"
52+
height={250}
53+
name="chart1"
54+
padding={{
55+
bottom: 50,
56+
left: 50,
57+
right: 200, // Adjusted to accommodate legend
58+
top: 50
59+
}}
60+
width={600}
61+
>
62+
<ChartAxis />
63+
<ChartAxis dependentAxis showGrid />
64+
<ChartGroup offset={11}>
65+
<ChartBar data={catsData} />
66+
<ChartBar data={dogsData} />
67+
<ChartBar data={birdsData} />
68+
<ChartBar data={miceData} />
69+
</ChartGroup>
70+
</Chart>
71+
</div>
72+
);
73+
};

0 commit comments

Comments
 (0)