-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy pathGroupedVerticalBarChart.Basic.Example.tsx
378 lines (367 loc) · 12.8 KB
/
GroupedVerticalBarChart.Basic.Example.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
import * as React from 'react';
import {
GroupedVerticalBarChart,
IGroupedVerticalBarChartProps,
DataVizPalette,
getColorFromToken,
} from '@fluentui/react-charting';
import { ChoiceGroup, IChoiceGroupOption } from '@fluentui/react/lib/ChoiceGroup';
import { Checkbox } from '@fluentui/react/lib/Checkbox';
import { Toggle } from '@fluentui/react/lib/Toggle';
interface IGroupedBarChartState {
width: number;
height: number;
barwidth: number;
selectedCallout: 'singleCallout' | 'StackCallout';
hideLabels: boolean;
enableGradient: boolean;
roundCorners: boolean;
selectMultipleLegends: boolean;
}
export class GroupedVerticalBarChartBasicExample extends React.Component<{}, IGroupedBarChartState> {
constructor(props: IGroupedVerticalBarChartProps) {
super(props);
this.state = {
width: 700,
height: 400,
barwidth: 16,
selectedCallout: 'singleCallout',
hideLabels: false,
enableGradient: false,
roundCorners: false,
selectMultipleLegends: false,
};
}
public componentDidMount(): void {
const style = document.createElement('style');
const focusStylingCSS = `
.containerDiv [contentEditable=true]:focus,
.containerDiv [tabindex]:focus,
.containerDiv area[href]:focus,
.containerDiv button:focus,
.containerDiv iframe:focus,
.containerDiv input:focus,
.containerDiv select:focus,
.containerDiv textarea:focus {
outline: -webkit-focus-ring-color auto 5px;
}
`;
style.appendChild(document.createTextNode(focusStylingCSS));
document.head.appendChild(style);
}
public render(): JSX.Element {
return <div>{this._basicExample()}</div>;
}
private _onWidthChange = (e: React.ChangeEvent<HTMLInputElement>) => {
this.setState({ width: parseInt(e.target.value, 10) });
};
private _onHeightChange = (e: React.ChangeEvent<HTMLInputElement>) => {
this.setState({ height: parseInt(e.target.value, 10) });
};
private _onBarwidthChange = (e: React.ChangeEvent<HTMLInputElement>) => {
this.setState({ barwidth: parseInt(e.target.value, 10) });
};
private _onChange = (ev: React.FormEvent<HTMLInputElement>, option: IChoiceGroupOption): void => {
this.setState({ selectedCallout: option.key as IGroupedBarChartState['selectedCallout'] });
};
private _onCheckChange = (ev: React.MouseEvent<HTMLElement>, checked: boolean) => {
this.setState({ hideLabels: checked });
};
private _onEnableGradientChange = (ev: React.MouseEvent<HTMLElement>, checked: boolean) => {
this.setState({ enableGradient: checked });
};
private _onRoundCornersChange = (ev: React.MouseEvent<HTMLElement>, checked: boolean) => {
this.setState({ roundCorners: checked });
};
private _onLegendMultiSelectChange = (ev: React.MouseEvent<HTMLElement>, checked: boolean) => {
this.setState({ selectMultipleLegends: checked });
};
private _basicExample(): JSX.Element {
const data = [
{
name: 'Jan - Mar',
series: [
{
key: 'series1',
data: 33000,
color: getColorFromToken(DataVizPalette.color3),
legend: '2022',
xAxisCalloutData: '2022/04/30',
yAxisCalloutData: '29%',
callOutAccessibilityData: {
ariaLabel: 'Group Jan - Mar 1 of 4, Bar series 1 of 2 2022, x value 2022/04/30, y value 29%',
},
},
{
key: 'series2',
data: 44000,
color: getColorFromToken(DataVizPalette.color4),
legend: '2023',
xAxisCalloutData: '2023/04/30',
yAxisCalloutData: '44%',
callOutAccessibilityData: {
ariaLabel: 'Group Jan - Mar 1 of 4, Bar series 2 of 2 2023, x value 2023/04/30, y value 44%',
},
},
{
key: 'series3',
data: 54000,
color: getColorFromToken(DataVizPalette.color5),
legend: '2024',
xAxisCalloutData: '2024/04/30',
yAxisCalloutData: '44%',
callOutAccessibilityData: {
ariaLabel: 'Group Jan - Mar 1 of 4, Bar series 3 of 4 2022, x value 2024/04/30, y value 44%',
},
},
{
key: 'series4',
data: 24000,
color: getColorFromToken(DataVizPalette.color6),
legend: '2021',
xAxisCalloutData: '2021/04/30',
yAxisCalloutData: '44%',
callOutAccessibilityData: {
ariaLabel: 'Group Jan - Mar 1 of 4, Bar series 4 of 4 2021, x value 2021/04/30, y value 44%',
},
},
],
},
{
name: 'Apr - Jun',
series: [
{
key: 'series1',
data: 33000,
color: getColorFromToken(DataVizPalette.color3),
legend: '2022',
xAxisCalloutData: '2022/05/30',
yAxisCalloutData: '29%',
callOutAccessibilityData: {
ariaLabel: 'Group Apr - Jun 2 of 4, Bar series 1 of 2 2022, x value 2022/05/30, y value 29%',
},
},
{
key: 'series2',
data: 3000,
color: getColorFromToken(DataVizPalette.color4),
legend: '2023',
xAxisCalloutData: '2023/05/30',
yAxisCalloutData: '3%',
callOutAccessibilityData: {
ariaLabel: 'Group Apr - Jun 2 of 4, Bar series 2 of 2 2023, x value 2023/05/30, y value 3%',
},
},
{
key: 'series3',
data: 9000,
color: getColorFromToken(DataVizPalette.color5),
legend: '2024',
xAxisCalloutData: '2024/05/30',
yAxisCalloutData: '3%',
callOutAccessibilityData: {
ariaLabel: 'Group Apr - Jun 2 of 4, Bar series 3 of 4 2024, x value 2024/05/30, y value 3%',
},
},
{
key: 'series4',
data: 12000,
color: getColorFromToken(DataVizPalette.color6),
legend: '2021',
xAxisCalloutData: '2021/05/30',
yAxisCalloutData: '3%',
callOutAccessibilityData: {
ariaLabel: 'Group Apr - Jun 2 of 4, Bar series 4 of 4 2021, x value 2021/05/30, y value 3%',
},
},
],
},
{
name: 'Jul - Sep',
series: [
{
key: 'series1',
data: 14000,
color: getColorFromToken(DataVizPalette.color3),
legend: '2022',
xAxisCalloutData: '2022/06/30',
yAxisCalloutData: '13%',
callOutAccessibilityData: {
ariaLabel: 'Group Jul - Sep 3 of 4, Bar series 1 of 2 2022, x value 2022/06/30, y value 13%',
},
},
{
key: 'series2',
data: 50000,
color: getColorFromToken(DataVizPalette.color4),
legend: '2023',
xAxisCalloutData: '2023/06/30',
yAxisCalloutData: '50%',
callOutAccessibilityData: {
ariaLabel: 'Group Jul - Sep 3 of 4, Bar series 2 of 2 2023, x value 2023/06/30, y value 50%',
},
},
{
key: 'series3',
data: 60000,
color: getColorFromToken(DataVizPalette.color5),
legend: '2024',
xAxisCalloutData: '2024/06/30',
yAxisCalloutData: '50%',
callOutAccessibilityData: {
ariaLabel: 'Group Jul - Sep 3 of 4, Bar series 3 of 4 2024, x value 2024/06/30, y value 50%',
},
},
{
key: 'series4',
data: 10000,
color: getColorFromToken(DataVizPalette.color6),
legend: '2021',
xAxisCalloutData: '2021/06/30',
yAxisCalloutData: '50%',
callOutAccessibilityData: {
ariaLabel: 'Group Jul - Sep 3 of 4, Bar series 4 of 4 2021, x value 2021/06/30, y value 50%',
},
},
],
},
{
name: 'Oct - Dec',
series: [
{
key: 'series1',
data: 33000,
color: getColorFromToken(DataVizPalette.color3),
legend: '2022',
xAxisCalloutData: '2022/07/30',
yAxisCalloutData: '29%',
callOutAccessibilityData: {
ariaLabel: 'Group Oct - Dec 4 of 4, Bar series 1 of 2 2022, x value 2022/07/30, y value 29%',
},
},
{
key: 'series2',
data: 3000,
color: getColorFromToken(DataVizPalette.color4),
legend: '2023',
xAxisCalloutData: '2023/07/30',
yAxisCalloutData: '3%',
callOutAccessibilityData: {
ariaLabel: 'Group Oct - Dec 4 of 4, Bar series 2 of 2 2023, x value 2023/07/30, y value 3%',
},
},
{
key: 'series3',
data: 6000,
color: getColorFromToken(DataVizPalette.color5),
legend: '2024',
xAxisCalloutData: '2024/07/30',
yAxisCalloutData: '3%',
callOutAccessibilityData: {
ariaLabel: 'Group Oct - Dec 4 of 4, Bar series 3 of 4 2024, x value 2024/07/30, y value 3%',
},
},
{
key: 'series4',
data: 15000,
color: getColorFromToken(DataVizPalette.color6),
legend: '2021',
xAxisCalloutData: '2021/07/30',
yAxisCalloutData: '3%',
callOutAccessibilityData: {
ariaLabel: 'Group Oct - Dec 4 of 4, Bar series 4 of 4 2021, x value 2021/07/30, y value 3%',
},
},
],
},
];
const options: IChoiceGroupOption[] = [
{ key: 'singleCallout', text: 'Single callout' },
{ key: 'StackCallout', text: 'Stack callout' },
];
const rootStyle = { width: `${this.state.width}px`, height: `${this.state.height}px` };
return (
<div className="containerDiv">
<div>
In this example the <code>xAxisCalloutData</code> property overrides the x value that is shown on the callout.
So instead of a numeric value, the callout will show the date that is passed in the{' '}
<code>xAxisCalloutData</code> property.
</div>
<label htmlFor="changeWidth_Basic">Change Width:</label>
<input
type="range"
value={this.state.width}
min={200}
max={1000}
id="changeWidth_Basic"
onChange={this._onWidthChange}
aria-valuetext={`ChangeWidthSlider${this.state.width}`}
/>
<label htmlFor="changeHeight_Basic">Change Height:</label>
<input
type="range"
value={this.state.height}
min={200}
max={1000}
id="changeHeight_Basic"
onChange={this._onHeightChange}
aria-valuetext={`ChangeHeightslider${this.state.height}`}
/>
<br />
<label htmlFor="changeBarwidth">Change Barwidth:</label>
<input
type="range"
value={this.state.barwidth}
min={1}
max={50}
id="changeBarwidth"
onChange={this._onBarwidthChange}
aria-valuetext={`ChangeBarwidthslider${this.state.barwidth}`}
/>
<label>{this.state.barwidth}</label>
<ChoiceGroup
options={options}
selectedKey={this.state.selectedCallout}
onChange={this._onChange}
label="Pick one"
/>
<Checkbox
label="Hide labels"
checked={this.state.hideLabels}
onChange={this._onCheckChange}
styles={{ root: { marginTop: '20px' } }}
/>
<div style={{ display: 'flex' }}>
<Toggle label="Enable Gradient" onText="ON" offText="OFF" onChange={this._onEnableGradientChange} />
<Toggle label="Rounded Corners" onText="ON" offText="OFF" onChange={this._onRoundCornersChange} />
<Toggle
label="Select Multiple Legends"
onText="ON"
offText="OFF"
onChange={this._onLegendMultiSelectChange}
/>
</div>
<div style={rootStyle}>
<GroupedVerticalBarChart
culture={window.navigator.language}
chartTitle="Grouped Vertical Bar chart basic example"
data={data}
height={this.state.height}
width={this.state.width}
isCalloutForStack={this.state.selectedCallout === 'StackCallout'}
barwidth={this.state.barwidth}
hideLabels={this.state.hideLabels}
enableReflow={true}
enableGradient={this.state.enableGradient}
roundCorners={this.state.roundCorners}
legendProps={{
canSelectMultipleLegends: this.state.selectMultipleLegends,
}}
/>
</div>
</div>
);
}
}