This repository was archived by the owner on Jul 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherror-bar.tsx
More file actions
221 lines (219 loc) · 11.9 KB
/
error-bar.tsx
File metadata and controls
221 lines (219 loc) · 11.9 KB
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
/**
* Sample for error bar
*/
import * as React from "react";
import * as ReactDOM from "react-dom";
import {
ChartComponent, SeriesCollectionDirective, SeriesDirective, ErrorBar, ScatterSeries, Tooltip, Category,
ILoadedEventArgs, ErrorBarMode, ErrorBarType, ErrorBarDirection, ChartTheme,
IPointRenderEventArgs, Inject
} from '@syncfusion/ej2-react-charts';
import { PropertyPane } from '../common/property-pane';
import { EmitType } from '@syncfusion/ej2-base';
import { SampleBase } from '../common/sample-base';
import { fabricColors, materialColors, bootstrapColors,highContrastColors } from './theme-color';
import { DropDownListComponent } from '@syncfusion/ej2-react-dropdowns';
import { CheckBoxComponent } from '@syncfusion/ej2-react-buttons';
import { NumericTextBoxComponent } from '@syncfusion/ej2-react-inputs';
export let data1: any[] = [
{ x: 'IND', y: 24 }, { x: 'AUS', y: 20 }, { x: 'USA', y: 35 },
{ x: 'DEU', y: 27 }, { x: 'ITA', y: 30 },
{ x: 'UK', y: 41 }, { x: 'RUS', y: 26 }
];
export let pointRender: EmitType<IPointRenderEventArgs> = (args: IPointRenderEventArgs): void => {
let selectedTheme: string = location.hash.split('/')[1];
selectedTheme = selectedTheme ? selectedTheme : 'material';
if (selectedTheme && selectedTheme.indexOf('fabric') > -1) {
args.fill = fabricColors[args.point.index % 10];
} else if (selectedTheme === 'material') {
args.fill = materialColors[args.point.index % 10];
} else if (selectedTheme === 'highcontrast') {
args.fill = highContrastColors[args.point.index % 10];
} else {
args.fill = bootstrapColors[args.point.index % 10];
}
};
const SAMPLE_CSS = `
.control-fluid {
padding: 0px !important;
}`;
export class ErrorBarChart extends SampleBase<{}, {}> {
private chartInstance: ChartComponent;
private checkElement: CheckBoxComponent;
private dropElement: DropDownListComponent;
private modeElement: DropDownListComponent;
private lengthElement: NumericTextBoxComponent;
private widthElement: NumericTextBoxComponent;
private vErrElement: NumericTextBoxComponent;
private hErrElement: NumericTextBoxComponent;
private directionElement: DropDownListComponent;
private change(): void {
this.chartInstance.series[0].errorBar.type = this.dropElement.value as ErrorBarType;
this.chartInstance.series[0].animation.enable = false;
this.chartInstance.refresh();
};
private mode(): void {
this.chartInstance.series[0].errorBar.mode = this.modeElement.value as ErrorBarMode;
this.chartInstance.series[0].animation.enable = false;
this.chartInstance.refresh();
};
private errorBarVisible(): void {
this.chartInstance.series[0].errorBar.visible = this.checkElement.checked;
this.chartInstance.series[0].animation.enable = false;
this.chartInstance.refresh();
}
private errDirection(): void {
this.chartInstance.series[0].errorBar.direction = this.directionElement.value as ErrorBarDirection;
this.chartInstance.series[0].animation.enable = false;
this.chartInstance.refresh();
}
private vError(): void {
this.chartInstance.series[0].errorBar.verticalError = this.vErrElement.value;
this.chartInstance.series[0].animation.enable = false;
this.chartInstance.refresh();
}
private hError(): void {
this.chartInstance.series[0].errorBar.horizontalError = this.hErrElement.value;
this.chartInstance.series[0].animation.enable = false;
this.chartInstance.refresh();
}
private type: { [key: string]: Object }[] = [
{ value: 'Fixed' },
{ value: 'Percentage' },
{ value: 'StandardDeviation' },
{ value: 'StandardError' },
{ value: 'Custom' }
];
private emode: { [key: string]: Object }[] = [
{ value: 'Vertical' },
{ value: 'Horizontal' },
{ value: 'Both' }
];
private directions: { [key: string]: Object }[] = [
{ value: 'Both' },
{ value: 'Minus' },
{ value: 'Plus' }
];
render() {
return (
<div className='control-pane'>
<style>
{SAMPLE_CSS}
</style>
<div className='control-section row'>
<div className='col-md-8'>
<ChartComponent id='charts' ref={chart => this.chartInstance = chart}
primaryXAxis={{
valueType: 'Category', interval: 1,
majorGridLines: { width: 0 }
}}
chartArea={{ border: { width: 0 } }}
primaryYAxis={{
labelFormat: '{value}%', minimum: 15, maximum: 45,
lineStyle: { width: 0 }
}}
pointRender={pointRender}
load={this.load.bind(this)}
title="Sales Distribution of Car by Region" loaded={this.onChartLoad.bind(this)}
tooltip={{ enable: true }}>
<Inject services={[ScatterSeries, Category, ErrorBar, Tooltip]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data1} xName='x' yName='y' type='Scatter' marker={{ height: 10, width: 10 }}
errorBar={{ visible: true, verticalError: 3, horizontalError: 3 }} width={2} name='Sales'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
</div>
<div className='col-md-4 property-section'>
<PropertyPane title='Properties'>
<table id='property' title='Properties' className='property-panel-table' style={{ width: '100%' }}>
<tr style={{ height: '50px' }}>
<td style={{ width: '60%' }}>
<div>Error Bar Type: </div>
</td>
<td style={{ width: '40%' }}>
<div>
<DropDownListComponent width={120} id="type" change={this.change.bind(this)} ref={d => this.dropElement = d} dataSource={this.type} fields={{ text: 'value', value: 'value' }} value="Fixed" />
</div>
</td>
</tr>
<tr style={{ height: '50px' }}>
<td style={{ width: '60%' }}>
<div>Drawing Mode: </div></td>
<td style={{ width: '40%' }}>
<div>
<DropDownListComponent width={120} id="modes" change={this.mode.bind(this)} ref={d => this.modeElement = d} dataSource={this.emode} fields={{ text: 'value', value: 'value' }} value="Vertical" />
</div>
</td>
</tr>
<tr style={{ height: '50px' }}>
<td style={{ width: '60%' }}>
<div>Drawing Direction: </div></td>
<td style={{ width: '40%' }}>
<div>
<DropDownListComponent width={120} id="directions" change={this.errDirection.bind(this)} ref={d => this.directionElement = d} dataSource={this.directions} fields={{ text: 'value', value: 'value' }} value="Both" />
</div>
</td>
</tr>
<tr style={{ height: '50px' }}>
<td style={{ width: '60%' }}>
<div>Vertical Error:</div>
</td>
<td style={{ padding: 10, width: '40%' }}>
<NumericTextBoxComponent width={120} value={3} min={1} max={20} step={1} change={this.vError.bind(this)} ref={d => this.vErrElement = d} />
</td>
</tr>
<tr style={{ height: '50px' }}>
<td style={{ width: '60%' }}>
<div>Horizontal Error:</div>
</td>
<td style={{ padding: 10, width: '40%' }}>
<NumericTextBoxComponent width={120} value={3} min={1} max={20} step={1} change={this.hError.bind(this)} ref={d => this.hErrElement = d} />
</td>
</tr>
</table>
</PropertyPane>
</div>
</div>
<div id="action-description">
<p>
This sample visualizes the errors in sales distribution of a car for a certain period with error bar in the chart. In property panel, the options are available to change error bar type, drawing mode, and drawing direction of error bar by means of dropdown
</p>
</div>
<div id="description">
<p>
In this example, you can see how to render and configure the error bar charts. Line type charts are used for cartesian type
series. You can use error bar by set <code>visible</code> property to true. You can change the error bar
rendering type using <code>type</code> property like fixedValue, percentage, standardDeviation, standardError and
custom option of errorBar. To change the error bar line length you can use <code>verticalError</code> property.
</p>
<p>Chart supports the following error bar types.</p>
<ul>
<li><code>Fixed</code> - Renders a fixed type error bar.</li>
<li><code>Percentage</code> - Renders a percentage type error bar.</li>
<li><code>StandardDeviation</code> - Renders a standard deviation type error bar.</li>
<li><code>StandardError</code> - Renders a standard error type error bar.</li>
<li><code>Custom</code> - Renders a custom type error bar.</li>
</ul>
<p><b>Injecting Module</b></p>
<p>
Chart component features are segregated into individual feature-wise modules. To use error bar, we need to inject
<code>ErrorBar</code> into the <code>@services</code> section.
</p>
<p>
More information on the smart axis labels can be found in this
<a target="_blank" href="http://ej2.syncfusion.com/react/documentation/chart/api-series.html#type-chartseriestype">documentation section</a>.
</p>
</div>
</div >
)
}
public onChartLoad(args: ILoadedEventArgs): void {
document.getElementById('charts').setAttribute('title', '');
};
public load(args: ILoadedEventArgs): void {
let selectedTheme: string = location.hash.split('/')[1];
selectedTheme = selectedTheme ? selectedTheme : 'Material';
args.chart.theme = (selectedTheme.charAt(0).toUpperCase() + selectedTheme.slice(1)) as ChartTheme;
};
}