Skip to content

Commit 2245261

Browse files
committed
converted remaining examples
1 parent 78fa650 commit 2245261

7 files changed

Lines changed: 452 additions & 333 deletions

File tree

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

Lines changed: 5 additions & 333 deletions
Original file line numberDiff line numberDiff line change
@@ -44,368 +44,40 @@ This demonstrates how to apply basic theme colors.
4444

4545
This demonstrates how to apply theme colors for ordered charts like bar, donut, pie, and stack.
4646

47-
```js
48-
import { ChartDonut, ChartThemeColor } from '@patternfly/react-charts/victory';
47+
```ts file = "ChartThemeMultiColorOrdered.tsx"
4948

50-
<div style={{ height: '230px', width: '350px' }}>
51-
<ChartDonut
52-
ariaDesc="Average number of pets"
53-
ariaTitle="Donut chart example"
54-
constrainToVisibleArea
55-
data={[{ x: 'Cats', y: 35 }, { x: 'Dogs', y: 55 }, { x: 'Birds', y: 10 }]}
56-
labels={({ datum }) => `${datum.x}: ${datum.y}%`}
57-
legendData={[{ name: 'Cats: 35' }, { name: 'Dogs: 55' }, { name: 'Birds: 10' }]}
58-
legendOrientation="vertical"
59-
legendPosition="right"
60-
name="chart2"
61-
padding={{
62-
bottom: 20,
63-
left: 20,
64-
right: 140, // Adjusted to accommodate legend
65-
top: 20
66-
}}
67-
subTitle="Pets"
68-
title="100"
69-
themeColor={ChartThemeColor.multiOrdered}
70-
width={350}
71-
/>
72-
</div>
7349
```
7450

7551
### Multi color (unordered)
7652

7753
This demonstrates how to apply theme colors for unordered charts like area, line, and sparkline.
7854

79-
```js
80-
import { Chart, ChartArea, ChartAxis, ChartGroup, ChartThemeColor, ChartVoronoiContainer } from '@patternfly/react-charts/victory';
55+
```ts file = "ChartThemeMultiColorUnordered.tsx"
8156

82-
<div style={{ height: '200px', width: '800px' }}>
83-
<Chart
84-
ariaDesc="Average number of pets"
85-
ariaTitle="Area chart example"
86-
containerComponent={<ChartVoronoiContainer labels={({ datum }) => `${datum.name}: ${datum.y}`} constrainToVisibleArea />}
87-
legendData={[{ name: 'Cats' }, { name: 'Dogs' }, { name: 'Birds' }]}
88-
legendOrientation="vertical"
89-
legendPosition="right"
90-
height={200}
91-
maxDomain={{y: 9}}
92-
name="chart3"
93-
padding={{
94-
bottom: 50,
95-
left: 50,
96-
right: 200, // Adjusted to accommodate legend
97-
top: 50
98-
}}
99-
themeColor={ChartThemeColor.multiUnordered}
100-
width={800}
101-
>
102-
<ChartAxis />
103-
<ChartAxis dependentAxis showGrid/>
104-
<ChartGroup>
105-
<ChartArea
106-
data={[
107-
{ name: 'Cats', x: '2015', y: 3 },
108-
{ name: 'Cats', x: '2016', y: 4 },
109-
{ name: 'Cats', x: '2017', y: 8 },
110-
{ name: 'Cats', x: '2018', y: 6 }
111-
]}
112-
interpolation="monotoneX"
113-
/>
114-
<ChartArea
115-
data={[
116-
{ name: 'Dogs', x: '2015', y: 2 },
117-
{ name: 'Dogs', x: '2016', y: 3 },
118-
{ name: 'Dogs', x: '2017', y: 4 },
119-
{ name: 'Dogs', x: '2018', y: 5 },
120-
{ name: 'Dogs', x: '2019', y: 6 }
121-
]}
122-
interpolation="monotoneX"
123-
/>
124-
<ChartArea
125-
data={[
126-
{ name: 'Birds', x: '2015', y: 1 },
127-
{ name: 'Birds', x: '2016', y: 2 },
128-
{ name: 'Birds', x: '2017', y: 3 },
129-
{ name: 'Birds', x: '2018', y: 2 },
130-
{ name: 'Birds', x: '2019', y: 4 }
131-
]}
132-
interpolation="monotoneX"
133-
/>
134-
</ChartGroup>
135-
</Chart>
136-
</div>
13757
```
13858

13959
### Custom color scale
14060

14161
This demonstrates an alternate way of applying a custom color scale and fill colors to individual charts.
14262

143-
```js
144-
import { Chart, ChartAxis, ChartBar, ChartLegend, ChartStack, ChartThemeColor, ChartTooltip } from '@patternfly/react-charts/victory';
145-
import chart_color_blue_300 from '@patternfly/react-tokens/dist/esm/chart_color_blue_300';
146-
import chart_color_green_300 from '@patternfly/react-tokens/dist/esm/chart_color_green_300';
147-
import chart_color_yellow_300 from '@patternfly/react-tokens/dist/esm/chart_color_yellow_300';
148-
import chart_color_purple_300 from '@patternfly/react-tokens/dist/esm/chart_color_purple_300';
63+
```ts file = "ChartThemeCustomColorScale.tsx"
14964

150-
<div style={{ height: '275px', width: '450px' }}>
151-
<Chart
152-
ariaDesc="Average number of pets"
153-
ariaTitle="Stack chart example"
154-
domainPadding={{ x: [30, 25] }}
155-
legendComponent={
156-
<ChartLegend
157-
data={[
158-
{
159-
name: 'Cats',
160-
symbol: { fill: chart_color_blue_300.var }
161-
},
162-
{
163-
name: 'Dogs',
164-
symbol: { fill: chart_color_yellow_300.var }
165-
},
166-
{
167-
name: 'Birds',
168-
symbol: { fill: chart_color_green_300.var }
169-
},
170-
{
171-
name: 'Mice',
172-
symbol: { fill: chart_color_purple_300.var }
173-
}
174-
]}
175-
/>
176-
}
177-
legendPosition="bottom-left"
178-
height={275}
179-
name="chart4"
180-
padding={{
181-
bottom: 75, // Adjusted to accommodate legend
182-
left: 50,
183-
right: 50,
184-
top: 50
185-
}}
186-
themeColor={ChartThemeColor.multiOrdered}
187-
width={450}
188-
>
189-
<ChartAxis />
190-
<ChartAxis dependentAxis showGrid />
191-
<ChartStack
192-
horizontal
193-
colorScale={[
194-
chart_color_blue_300.var,
195-
chart_color_yellow_300.var,
196-
chart_color_green_300.var,
197-
chart_color_purple_300.var
198-
]}
199-
>
200-
<ChartBar
201-
data={[
202-
{ name: 'Cats', x: '2015', y: 1, label: 'Cats: 1' },
203-
{ name: 'Cats', x: '2016', y: 2, label: 'Cats: 2' },
204-
{ name: 'Cats', x: '2017', y: 5, label: 'Cats: 5' },
205-
{ name: 'Cats', x: '2018', y: 3, label: 'Cats: 3' }
206-
]}
207-
labelComponent={<ChartTooltip constrainToVisibleArea />}
208-
/>
209-
<ChartBar
210-
data={[
211-
{ name: 'Dogs', x: '2015', y: 2, label: 'Dogs: 2' },
212-
{ name: 'Dogs', x: '2016', y: 1, label: 'Dogs: 1' },
213-
{ name: 'Dogs', x: '2017', y: 7, label: 'Dogs: 7' },
214-
{ name: 'Dogs', x: '2018', y: 4, label: 'Dogs: 4' }
215-
]}
216-
labelComponent={<ChartTooltip constrainToVisibleArea />}
217-
/>
218-
<ChartBar
219-
data={[
220-
{ name: 'Birds', x: '2015', y: 4, label: 'Birds: 4' },
221-
{ name: 'Birds', x: '2016', y: 4, label: 'Birds: 4' },
222-
{ name: 'Birds', x: '2017', y: 9, label: 'Birds: 9' },
223-
{ name: 'Birds', x: '2018', y: 7, label: 'Birds: 7' }
224-
]}
225-
labelComponent={<ChartTooltip constrainToVisibleArea />}
226-
/>
227-
<ChartBar
228-
data={[
229-
{ name: 'Mice', x: '2015', y: 3, label: 'Mice: 3' },
230-
{ name: 'Mice', x: '2016', y: 3, label: 'Mice: 3' },
231-
{ name: 'Mice', x: '2017', y: 8, label: 'Mice: 8' },
232-
{ name: 'Mice', x: '2018', y: 5, label: 'Mice: 5' }
233-
]}
234-
labelComponent={<ChartTooltip constrainToVisibleArea />}
235-
/>
236-
</ChartStack>
237-
</Chart>
238-
</div>
23965
```
24066

24167
### Custom stroke color
24268

24369
This demonstrates an alternate way of applying custom stroke and fill colors to a threshold chart.
24470

245-
```js
246-
import { Chart, ChartAxis, ChartGroup, ChartLine, ChartThemeColor, ChartThreshold, ChartVoronoiContainer } from '@patternfly/react-charts/victory';
247-
import chart_color_blue_300 from '@patternfly/react-tokens/dist/esm/chart_color_blue_300';
71+
```ts file = "ChartThemeCustomStrokeColor.tsx"
24872

249-
<div style={{ height: '275px', width: '450px' }}>
250-
<Chart
251-
ariaDesc="Average number of pets"
252-
ariaTitle="Line chart example"
253-
containerComponent={<ChartVoronoiContainer labels={({ datum }) => `${datum.name}: ${datum.y}`} constrainToVisibleArea />}
254-
legendData={[
255-
{ name: 'Cats' },
256-
{ name: 'Birds' },
257-
{ name: 'Mice' },
258-
{ name: 'Cats Threshold', symbol: { fill: chart_color_blue_300.var, type: 'threshold' }}
259-
]}
260-
legendPosition="bottom"
261-
height={275}
262-
maxDomain={{y: 10}}
263-
minDomain={{y: 0}}
264-
name="chart5"
265-
padding={{
266-
bottom: 75, // Adjusted to accommodate legend
267-
left: 50,
268-
right: 50,
269-
top: 50
270-
}}
271-
themeColor={ChartThemeColor.multiUnordered}
272-
width={450}
273-
>
274-
<ChartAxis tickValues={[2, 3, 4]} />
275-
<ChartAxis dependentAxis showGrid tickValues={[2, 5, 8]} />
276-
<ChartGroup>
277-
<ChartLine
278-
data={[
279-
{ name: 'Cats', x: '2015', y: 1 },
280-
{ name: 'Cats', x: '2016', y: 2 },
281-
{ name: 'Cats', x: '2017', y: 5 },
282-
{ name: 'Cats', x: '2018', y: 3 }
283-
]}
284-
/>
285-
<ChartLine
286-
data={[
287-
{ name: 'Birds', x: '2015', y: 3 },
288-
{ name: 'Birds', x: '2016', y: 4 },
289-
{ name: 'Birds', x: '2017', y: 9 },
290-
{ name: 'Birds', x: '2018', y: 5 }
291-
]}
292-
/>
293-
<ChartLine
294-
data={[
295-
{ name: 'Mice', x: '2015', y: 3 },
296-
{ name: 'Mice', x: '2016', y: 3 },
297-
{ name: 'Mice', x: '2017', y: 8 },
298-
{ name: 'Mice', x: '2018', y: 7 }
299-
]}
300-
/>
301-
<ChartThreshold
302-
data={[
303-
{ name: 'Cats Threshold', x: '2015', y: 5 },
304-
{ name: 'Cats Threshold', x: '2016', y: 5 },
305-
{ name: 'Cats Threshold', x: '2016', y: 6 },
306-
{ name: 'Cats Threshold', x: '2017', y: 6 },
307-
{ name: 'Cats Threshold', x: '2018', y: 6 }
308-
]}
309-
style={{
310-
data: {
311-
stroke: chart_color_blue_300.var,
312-
}
313-
}}
314-
/>
315-
</ChartGroup>
316-
</Chart>
317-
</div>
31873
```
31974

32075
### Custom theme
32176

32277
This demonstrates custom theme properties, which may be applied across multiple charts.
32378

324-
```js
325-
import { Chart, ChartBar, ChartAxis, ChartGroup, ChartThemeColor, ChartVoronoiContainer, getCustomTheme } from '@patternfly/react-charts/victory';
326-
import chart_color_blue_300 from '@patternfly/react-tokens/dist/esm/chart_color_blue_300';
327-
import chart_color_green_300 from '@patternfly/react-tokens/dist/esm/chart_color_green_300';
328-
import chart_color_teal_300 from '@patternfly/react-tokens/dist/esm/chart_color_teal_300';
329-
import chart_color_yellow_300 from '@patternfly/react-tokens/dist/esm/chart_color_yellow_300';
330-
331-
class MultiColorChart extends React.Component {
332-
constructor(props) {
333-
super(props);
334-
335-
// Colors
336-
this.colorScale = [
337-
chart_color_blue_300.var,
338-
chart_color_green_300.var,
339-
chart_color_teal_300.var,
340-
chart_color_yellow_300.var
341-
];
342-
343-
// Layout
344-
this.layoutProps = {
345-
padding: {
346-
bottom: 50,
347-
left: 50,
348-
right: 200, // Adjusted to accommodate legend
349-
top: 50
350-
}
351-
};
352-
353-
// Victory theme properties only
354-
this.themeProps = {
355-
bar: {
356-
colorScale: this.colorScale,
357-
...this.layoutProps,
358-
},
359-
chart: {
360-
colorScale: this.colorScale,
361-
...this.layoutProps,
362-
},
363-
group: {
364-
colorScale: this.colorScale,
365-
...this.layoutProps,
366-
},
367-
legend: {
368-
colorScale: this.colorScale
369-
}
370-
};
371-
372-
// Applies theme color and variant to base theme
373-
this.myCustomTheme = getCustomTheme(
374-
ChartThemeColor.default,
375-
this.themeProps
376-
);
377-
}
79+
```ts file = "ChartThemeCustomTheme.tsx"
37880

379-
render() {
380-
return (
381-
<div style={{ height: '250px', width: '600px' }}>
382-
<Chart
383-
ariaDesc="Average number of pets"
384-
ariaTitle="Bar chart example"
385-
containerComponent={<ChartVoronoiContainer labels={({ datum }) => `${datum.name}: ${datum.y}`} constrainToVisibleArea />}
386-
domain={{y: [0,9]}}
387-
domainPadding={{ x: [30, 25] }}
388-
legendData={[{ name: 'Cats' }, { name: 'Dogs' }, { name: 'Birds' }, { name: 'Mice' }]}
389-
legendOrientation="vertical"
390-
legendPosition="right"
391-
height={250}
392-
name="chart6"
393-
theme={this.myCustomTheme}
394-
width={600}
395-
>
396-
<ChartAxis />
397-
<ChartAxis dependentAxis showGrid />
398-
<ChartGroup offset={11}>
399-
<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 }]} />
400-
<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 }]} />
401-
<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 }]} />
402-
<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 }]} />
403-
</ChartGroup>
404-
</Chart>
405-
</div>
406-
);
407-
}
408-
}
40981
```
41082

41183
## Documentation

0 commit comments

Comments
 (0)