Skip to content

Commit b9083cb

Browse files
Integrated latest changes at 06-25-2024 4:30:12 PM
1 parent b0f63f7 commit b9083cb

File tree

2,651 files changed

+40823
-2016079
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,651 files changed

+40823
-2016079
lines changed

ej2-react/chart/working-with-data.md

Lines changed: 102 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ domainurl: ##DomainURL##
1212

1313
# Working with data in React Chart component
1414

15-
Chart can visualise data bound from local or remote data.
15+
Chart can visualize data bound from local or remote data.
1616

17-
## Local Data
17+
## Local data
1818

1919
You can bind a simple JSON data to the chart using [`dataSource`](https://ej2.syncfusion.com/react/documentation/api/chart/seriesModel/#datasource)property in series. Now map the fields in JSON to [`xName`](https://ej2.syncfusion.com/react/documentation/api/chart/seriesModel/#xname) and [`yName`](https://ej2.syncfusion.com/react/documentation/api/chart/seriesModel/#yname) properties.
2020

@@ -27,7 +27,7 @@ You can bind a simple JSON data to the chart using [`dataSource`](https://ej2.sy
2727
{% endhighlight %}
2828
{% endtabs %}
2929

30-
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs8" %}
30+
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs8" %}
3131

3232
## Lazy loading
3333

@@ -42,9 +42,9 @@ Lazy loading allows you to load data for chart on demand. Chart will fire the sc
4242
{% endhighlight %}
4343
{% endtabs %}
4444

45-
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs9" %}
45+
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs9" %}
4646

47-
### Common Datasource
47+
### Common datasource
4848

4949
You can also bind a JSON data common to all series using [`dataSource`](https://ej2.syncfusion.com/react/documentation/api/chart/seriesModel/#datasource) property in chart.
5050

@@ -57,9 +57,9 @@ You can also bind a JSON data common to all series using [`dataSource`](https:/
5757
{% endhighlight %}
5858
{% endtabs %}
5959

60-
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs10" %}
60+
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs10" %}
6161

62-
## Remote Data
62+
## Remote data
6363

6464
You can also bind remote data to the chart using `DataManager`. The DataManager requires minimal information like webservice URL, adaptor and crossDomain to interact with service endpoint properly. Assign the instance of DataManager to the [`dataSource`](https://ej2.syncfusion.com/react/documentation/api/chart/seriesModel/#datasource) property in series and map the fields of data to [`xName`](https://ej2.syncfusion.com/react/documentation/api/chart/seriesModel/#xname) and [`yName`](https://ej2.syncfusion.com/react/documentation/api/chart/seriesModel/#yname) properties. You can also use the [`query`](https://ej2.syncfusion.com/react/documentation/api/chart/seriesModel/#query) property of the series to filter the data.
6565

@@ -72,7 +72,99 @@ You can also bind remote data to the chart using `DataManager`. The DataManager
7272
{% endhighlight %}
7373
{% endtabs %}
7474

75-
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs11" %}
75+
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs11" %}
76+
77+
## Binding data using ODataAdaptor
78+
79+
[`OData`](http://www.odata.org/documentation/odata-version-3-0/) is a standardized protocol for creating and consuming data. You can retrieve data from an OData service using the DataManager. Refer to the following code example for remote data binding using an OData service.
80+
81+
{% tabs %}
82+
{% highlight js tabtitle="index.jsx" %}
83+
{% include code-snippet/chart/series/column-cs14/app/index.jsx %}
84+
{% endhighlight %}
85+
{% highlight ts tabtitle="index.tsx" %}
86+
{% include code-snippet/chart/series/column-cs14/app/index.tsx %}
87+
{% endhighlight %}
88+
{% endtabs %}
89+
90+
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs14" %}
91+
92+
## Binding data using ODataV4Adaptor
93+
94+
ODataV4 is an improved version of the OData protocols, and the `DataManager` can also retrieve and consume ODataV4 services. For more details on ODataV4 services, refer to the [`odata documentation`](http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part1-protocol/odata-v4.0-errata03-os-part1-protocol-complete.html#_Toc453752197). To bind an ODataV4 service, use the **ODataV4Adaptor**.
95+
96+
{% tabs %}
97+
{% highlight js tabtitle="index.jsx" %}
98+
{% include code-snippet/chart/series/column-cs15/app/index.jsx %}
99+
{% endhighlight %}
100+
{% highlight ts tabtitle="index.tsx" %}
101+
{% include code-snippet/chart/series/column-cs15/app/index.tsx %}
102+
{% endhighlight %}
103+
{% endtabs %}
104+
105+
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs15" %}
106+
107+
## Web API adaptor
108+
109+
You can use the **WebApiAdaptor** to bind the chart with a Web API created using an OData endpoint.
110+
111+
{% tabs %}
112+
{% highlight js tabtitle="index.jsx" %}
113+
{% include code-snippet/chart/series/column-cs16/app/index.jsx %}
114+
{% endhighlight %}
115+
{% highlight ts tabtitle="index.tsx" %}
116+
{% include code-snippet/chart/series/column-cs16/app/index.tsx %}
117+
{% endhighlight %}
118+
{% endtabs %}
119+
120+
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs16" %}
121+
122+
The response object should contain the properties **Items** and **Count**, where **Items** represents a collection of entities, and **Count** represents the total number of entities.
123+
124+
The sample response object should appear as follows:
125+
126+
```
127+
{
128+
Items: [{..}, {..}, {..}, ...],
129+
Count: 830
130+
}
131+
```
132+
133+
## Custom adaptor
134+
135+
You can create your own adaptor by extending the built-in adaptors. The following demonstrates the custom adaptor approach and how to add a serial number to the records by overriding the built-in response processing using the **processResponse** method of the **ODataAdaptor**.
136+
137+
{% tabs %}
138+
{% highlight js tabtitle="index.jsx" %}
139+
{% include code-snippet/chart/series/column-cs17/app/index.jsx %}
140+
{% endhighlight %}
141+
{% highlight ts tabtitle="index.tsx" %}
142+
{% include code-snippet/chart/series/column-cs17/app/index.tsx %}
143+
{% endhighlight %}
144+
{% highlight js tabtitle="serialnoadaptor.jsx" %}
145+
{% include code-snippet/chart/series/column-cs17/app/serialNoAdaptor.jsx %}
146+
{% endhighlight %}
147+
{% highlight ts tabtitle="serialnoadaptor.tsx" %}
148+
{% include code-snippet/chart/series/column-cs17/app/serialNoAdaptor.tsx %}
149+
{% endhighlight %}
150+
{% endtabs %}
151+
152+
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs17" %}
153+
154+
## Offline mode
155+
156+
When using remote data binding, all chart actions will be processed on the server-side. To avoid postback for every action, configure the chart to load all data upon initialization and handle actions on the client-side. To enable this behavior, utilize the **offline** property of the `DataManager`.
157+
158+
{% tabs %}
159+
{% highlight js tabtitle="index.jsx" %}
160+
{% include code-snippet/chart/series/column-cs18/app/index.jsx %}
161+
{% endhighlight %}
162+
{% highlight ts tabtitle="index.tsx" %}
163+
{% include code-snippet/chart/series/column-cs18/app/index.tsx %}
164+
{% endhighlight %}
165+
{% endtabs %}
166+
167+
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs18" %}
76168

77169
## Empty points
78170

@@ -87,7 +179,7 @@ The Data points that uses the `null` or `undefined` as value are considered as e
87179
{% endhighlight %}
88180
{% endtabs %}
89181

90-
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs12" %}
182+
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs12" %}
91183

92184
**Empty point color**
93185

@@ -102,4 +194,4 @@ Specific color for empty point can be set by `fill` property in `emptyPointSetti
102194
{% endhighlight %}
103195
{% endtabs %}
104196

105-
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs13" %}
197+
{% previewsample "page.domainurl/code-snippet/chart/series/column-cs13" %}

ej2-react/code-snippet/chart/dynamic-update/click-add-point/app/index.jsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,24 @@ function App() {
4141
const chartMouseClick = (args) => {
4242
let isRemoved = false;
4343
if (args.axisData) {
44-
for (let i = 0; i < (chartInstance.current.series[0]).points.length; i++) {
45-
const markerWidth = (chartInstance.current.series[0]).marker.width / 2;
44+
for (let i = 0; i < (chartInstance.series[0]).points.length; i++) {
45+
const markerWidth = (chartInstance.series[0]).marker.width / 2;
4646
let roundedX = Math.round(args.axisData['primaryXAxis']) + markerWidth;
4747
let roundedY = Math.round(args.axisData['primaryYAxis']) + markerWidth;
48-
let pointX = Math.round((chartInstance.current.series[0]).points[i].x) + markerWidth;
49-
let pointY = Math.round((chartInstance.current.series[0]).points[i].y) + markerWidth;
48+
let pointX = Math.round((chartInstance.series[0]).points[i].x) + markerWidth;
49+
let pointY = Math.round((chartInstance.series[0]).points[i].y) + markerWidth;
5050
if ((roundedX === pointX || roundedX + 1 === pointX || roundedX - 1 === pointX) &&
5151
(roundedY === pointY || roundedY + 1 === pointY || roundedY - 1 === pointY)) {
52-
if ((chartInstance.current.series[0]).points.length > 1) {
53-
const points = (chartInstance.current.series[0]).points;
52+
if ((chartInstance.series[0]).points.length > 1) {
53+
const points = (chartInstance.series[0]).points;
5454
const duration = i === 0 || i === points[points.length - 1].index ? 500 : 0;
55-
chartInstance.current.series[0].removePoint(i, duration);
55+
chartInstance.series[0].removePoint(i, duration);
5656
}
5757
isRemoved = true;
5858
}
5959
}
6060
if (!isRemoved) {
61-
chartInstance.current.series[0].addPoint({ x: Math.round(args.axisData['primaryXAxis']), y: Math.round(args.axisData['primaryYAxis']) });
61+
chartInstance.series[0].addPoint({ x: Math.round(args.axisData['primaryXAxis']), y: Math.round(args.axisData['primaryYAxis']) });
6262
}
6363
}
6464
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{% raw %}
2+
3+
4+
import * as React from "react";
5+
import * as ReactDOM from "react-dom";
6+
import { DataManager, Query, ODataAdaptor } from '@syncfusion/ej2-data';
7+
import { ChartComponent, Inject, SeriesCollectionDirective, SeriesDirective, Category, ColumnSeries } from '@syncfusion/ej2-react-charts';
8+
function App() {
9+
const dataManager = new DataManager({
10+
url: 'https://services.odata.org/V3/Northwind/Northwind.svc/Orders/',
11+
adaptor: new ODataAdaptor(),
12+
crossDomain: true
13+
});
14+
const query = new Query();
15+
const primaryxAxis = { valueType: 'Category' };
16+
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} title="Order Details">
17+
<Inject services={[ColumnSeries, Category]} />
18+
<SeriesCollectionDirective>
19+
<SeriesDirective dataSource={dataManager} xName='CustomerID' type='Column' yName='Freight' query={query} />
20+
</SeriesCollectionDirective>
21+
</ChartComponent>;
22+
}
23+
;
24+
export default App;
25+
ReactDOM.render(<App />, document.getElementById("charts"));
26+
27+
28+
{% endraw %}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{% raw %}
2+
3+
4+
import * as React from "react";
5+
import * as ReactDOM from "react-dom";
6+
import { DataManager, Query, ODataAdaptor } from '@syncfusion/ej2-data'
7+
import { AxisModel, ChartComponent, Inject, SeriesCollectionDirective, SeriesDirective, Category, ColumnSeries } from '@syncfusion/ej2-react-charts';
8+
9+
function App() {
10+
11+
const dataManager = new DataManager({
12+
url: 'https://services.odata.org/V3/Northwind/Northwind.svc/Orders/',
13+
adaptor: new ODataAdaptor(),
14+
crossDomain: true
15+
});
16+
const query = new Query();
17+
const primaryxAxis: AxisModel = { valueType: 'Category' };
18+
19+
return <ChartComponent id='charts'
20+
primaryXAxis={primaryxAxis}
21+
title="Order Details">
22+
<Inject services={[ColumnSeries, Category]} />
23+
<SeriesCollectionDirective>
24+
<SeriesDirective dataSource={dataManager} type='Column' xName='CustomerID' yName='Freight' query={query} />
25+
</SeriesCollectionDirective>
26+
</ChartComponent>
27+
28+
};
29+
export default App;
30+
ReactDOM.render(<App />, document.getElementById("charts"));
31+
32+
33+
{% endraw %}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<title>Syncfusion React Chart-Column Series</title>
6+
<meta charset="utf-8" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
<meta name="description" content="Essential JS 2 for React Components" />
9+
<meta name="author" content="Syncfusion" />
10+
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
11+
<script src="systemjs.config.js"></script>
12+
<style>
13+
#loader {
14+
color: #008cff;
15+
height: 40px;
16+
left: 45%;
17+
position: absolute;
18+
top: 45%;
19+
width: 30%;
20+
}
21+
#charts {
22+
height : 350px;
23+
display: block;
24+
}
25+
</style>
26+
</head>
27+
28+
<body>
29+
<div id='charts'>
30+
<div id='loader'>Loading....</div>
31+
</div>
32+
</body>
33+
34+
</html>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
System.config({
2+
transpiler: "ts",
3+
typescriptOptions: {
4+
target: "es5",
5+
module: "commonjs",
6+
moduleResolution: "node",
7+
emitDecoratorMetadata: true,
8+
experimentalDecorators: true,
9+
"jsx": "react"
10+
},
11+
meta: {
12+
'typescript': {
13+
"exports": "ts"
14+
}
15+
},
16+
paths: {
17+
"syncfusion:": "https://cdn.syncfusion.com/ej2/20.3.56/"
18+
},
19+
map: {
20+
app: 'app',
21+
ts: "https://unpkg.com/plugin-typescript@4.0.10/lib/plugin.js",
22+
typescript: "https://unpkg.com/typescript@2.2.2/lib/typescript.js",
23+
"@syncfusion/ej2-base": "syncfusion:ej2-base/dist/ej2-base.umd.min.js",
24+
"@syncfusion/ej2-data": "syncfusion:ej2-data/dist/ej2-data.umd.min.js",
25+
"@syncfusion/ej2-charts": "syncfusion:ej2-charts/dist/ej2-charts.umd.min.js",
26+
"@syncfusion/ej2-pdf-export": "syncfusion:ej2-pdf-export/dist/ej2-pdf-export.umd.min.js",
27+
"@syncfusion/ej2-file-utils": "syncfusion:ej2-file-utils/dist/ej2-file-utils.umd.min.js",
28+
"@syncfusion/ej2-compression": "syncfusion:ej2-compression/dist/ej2-compression.umd.min.js",
29+
"@syncfusion/ej2-react-base": "syncfusion:ej2-react-base/dist/ej2-react-base.umd.min.js",
30+
"@syncfusion/ej2-react-charts": "syncfusion:ej2-react-charts/dist/ej2-react-charts.umd.min.js",
31+
"@syncfusion/ej2-react-buttons": "syncfusion:ej2-react-buttons/dist/ej2-react-buttons.umd.min.js",
32+
"@syncfusion/ej2-react-popups": "syncfusion:ej2-react-popups/dist/ej2-react-popups.umd.min.js",
33+
"@syncfusion/ej2-navigations": "syncfusion:ej2-navigations/dist/ej2-navigations.umd.min.js",
34+
"@syncfusion/ej2-calendars": "syncfusion:ej2-calendars/dist/ej2-calendars.umd.min.js",
35+
"@syncfusion/ej2-lists": "syncfusion:ej2-lists/dist/ej2-lists.umd.min.js",
36+
"@syncfusion/ej2-inputs": "syncfusion:ej2-inputs/dist/ej2-inputs.umd.min.js",
37+
"@syncfusion/ej2-svg-base": "syncfusion:ej2-svg-base/dist/ej2-svg-base.umd.min.js",
38+
"@syncfusion/ej2-splitbuttons": "syncfusion:ej2-splitbuttons/dist/ej2-splitbuttons.umd.min.js",
39+
"@syncfusion/ej2-popups": "syncfusion:ej2-popups/dist/ej2-popups.umd.min.js",
40+
"@syncfusion/ej2-buttons": "syncfusion:ej2-buttons/dist/ej2-buttons.umd.min.js",
41+
"@syncfusion/ej2-excel-export": "syncfusion:ej2-excel-export/dist/ej2-excel-export.umd.min.js",
42+
"react-dom":"https://unpkg.com/react-dom@16.3.1/umd/react-dom.development.js",
43+
"react":"https://unpkg.com/react@16.3.1/umd/react.development.js",
44+
45+
},
46+
packages: {
47+
'app': { main: 'index', defaultExtension: 'tsx' },
48+
}
49+
50+
});
51+
52+
System.import('app');
53+
54+
55+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{% raw %}
2+
3+
4+
import * as React from "react";
5+
import * as ReactDOM from "react-dom";
6+
import { DataManager, Query, ODataV4Adaptor } from '@syncfusion/ej2-data';
7+
import { ChartComponent, Inject, SeriesCollectionDirective, SeriesDirective, Category, ColumnSeries } from '@syncfusion/ej2-react-charts';
8+
function App() {
9+
const dataManager = new DataManager({
10+
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/Orders',
11+
adaptor: new ODataV4Adaptor()
12+
});
13+
const query = new Query();
14+
const primaryxAxis = { valueType: 'Category' };
15+
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} title="Order Details">
16+
<Inject services={[ColumnSeries, Category]} />
17+
<SeriesCollectionDirective>
18+
<SeriesDirective dataSource={dataManager} type='Column' xName='CustomerID' yName='Freight' query={query} />
19+
</SeriesCollectionDirective>
20+
</ChartComponent>;
21+
}
22+
;
23+
export default App;
24+
ReactDOM.render(<App />, document.getElementById("charts"));
25+
26+
27+
{% endraw %}

0 commit comments

Comments
 (0)