Skip to content

Commit f77eaf3

Browse files
authored
Merge pull request #476 from Esri/tomwayson-patch-1
add info on using Cedar in modern web applications
2 parents fa484de + 7d1ddaa commit f77eaf3

File tree

1 file changed

+79
-49
lines changed

1 file changed

+79
-49
lines changed

README.md

Lines changed: 79 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,52 @@ You are looking at the documentation for v1.x of cedar. You can also view the [d
2121

2222
**NOTE:** If you want to use cedar in an Ember.js application, see [ember-cli-cedar](https://github.com/Esri/ember-cli-cedar) instead.
2323

24-
You can install cedar and it's [dependencies](#dependencies) from npm:
24+
You can install cedar and it's [dependencies](#dependencies) with npm:
2525
```bash
26-
npm install @esri/arcgis-rest-feature-layer@^2.0.0
27-
npm install @esri/arcgis-rest-request@^2.0.0
28-
npm install @esri/cedar
26+
npm install --save @esri/arcgis-rest-feature-layer@^2.0.0 @esri/arcgis-rest-request@^2.0.0 amcharts3 @esri/cedar
2927
```
3028

3129
or yarn:
3230

3331
```bash
34-
yarn add @esri/arcgis-rest-feature-layer@^2.0.0
35-
yarn add @esri/arcgis-rest-request@^2.0.0
36-
yarn add @esri/cedar
32+
yarn add @esri/arcgis-rest-feature-layer@^2.0.0 @esri/arcgis-rest-request@^2.0.0 amcharts3 @esri/cedar
3733
```
3834

39-
Alternatively, you can get cedar from the [unpkg.com](https://unpkg.com/) CDN as shown below.
35+
Alternatively, you can get cedar from the [unpkg.com](https://unpkg.com/) CDN as [shown below](#from-a-cdn).
36+
37+
### Importing Cedar
38+
39+
If you're using Cedar in a modern web application built with a bundler like [webpack](https://webpack.js.org/), you can load Cedar and its [dependencies](#dependencies) using `import` statements.
40+
41+
```js
42+
// import the amCharts base library
43+
import "amcharts3/amcharts/amcharts";
44+
// in this case, we only need bar charts, so we'll import the appropriate amCharts module
45+
import "amcharts3/amcharts/serial";
46+
// optionally import an amcharts theme; cedar provides a calcite theme
47+
import "@esri/cedar/dist/umd/themes/amCharts/calcite.js";
48+
// import the cedar Chart class
49+
import { Chart } from "@esri/cedar"
50+
```
51+
52+
If you need to use other chart types, or want to use amCharts plugins, import the appropriate amCharts modules _before importing cedar_:
53+
54+
```js
55+
// for pie charts
56+
import "amcharts3/amcharts/pie";
57+
// for scatter and bubble charts
58+
import "amcharts3/amcharts/xy";
59+
// for radar charts
60+
import "amcharts3/amcharts/radar";
61+
```
62+
63+
See the [amCharts documentation](https://github.com/amcharts/amcharts3) for more information on the available amCharts modules.
4064

4165
### Loading Cedar
4266

43-
You can load Cedar and its [dependencies](#dependencies) by including script tags that point to the CDN or your locally installed versions of these libraries. This will make the `cedar` global available to your application.
67+
Instead of [installing](installing-cedar) and [importing](importing-cedar) Cedar, you can load Cedar and its [dependencies](#dependencies) by including script tags that point to the CDN (or your locally installed versions of these libraries). This will make the `cedar` global available to your application.
68+
69+
#### From a CDN
4470

4571
```html
4672
<!-- load the amCharts base library -->
@@ -80,47 +106,51 @@ Once cedar is loaded you can create and show the chart at a designated element.
80106

81107
Then add a script that will configure cedar and render the chart:
82108

83-
```html
84-
<script>
85-
// connect to the data
86-
var datasets = [{
87-
"url": "https://services.arcgis.com/uDTUpUPbk8X8mXwl/arcgis/rest/services/Public_Schools_in_Onondaga_County/FeatureServer/0",
88-
"name": "schools",
89-
"query": {
90-
"orderByFields": "Number_of_SUM DESC",
91-
"groupByFieldsForStatistics": "Type",
92-
"outStatistics": [{
93-
"statisticType": "sum",
94-
"onStatisticField": "Number_of",
95-
"outStatisticFieldName": "Number_of_SUM"
96-
}]
97-
}
98-
}];
99-
100-
// designate a one or more series to show the data on the chart
101-
var series = [{
102-
"category": {"field": "Type", "label": "Type"},
103-
"value": {"field": "Number_of_SUM", "label": "Number of Students"},
104-
"source": "schools"
105-
}];
106-
107-
// optionally override any of the cart type's default styles
108-
var overrides = {
109-
"categoryAxis": {
110-
"labelRotation": -45
111-
}
109+
```js
110+
// connect to the data
111+
var datasets = [{
112+
"url": "https://services.arcgis.com/uDTUpUPbk8X8mXwl/arcgis/rest/services/Public_Schools_in_Onondaga_County/FeatureServer/0",
113+
"name": "schools",
114+
"query": {
115+
"orderByFields": "Number_of_SUM DESC",
116+
"groupByFieldsForStatistics": "Type",
117+
"outStatistics": [{
118+
"statisticType": "sum",
119+
"onStatisticField": "Number_of",
120+
"outStatisticFieldName": "Number_of_SUM"
121+
}]
112122
}
113-
114-
//create a cedar chart using the known 'bar' type
115-
var elementId = 'chart';
116-
var chart = new cedar.Chart(elementId, {"type": "bar"})
117-
.datasets(datasets)
118-
.series(series)
119-
.overrides(overrides);
120-
121-
// render the chart
122-
chart.show();
123-
</script>
123+
}];
124+
125+
// designate a one or more series to show the data on the chart
126+
var series = [{
127+
"category": {"field": "Type", "label": "Type"},
128+
"value": {"field": "Number_of_SUM", "label": "Number of Students"},
129+
"source": "schools"
130+
}];
131+
132+
// optionally override any of the cart type's default styles
133+
var overrides = {
134+
"categoryAxis": {
135+
"labelRotation": -45
136+
}
137+
}
138+
139+
//create a cedar chart using the known 'bar' type
140+
var elementId = 'chart';
141+
// NOTE: the following line assumes you've imported Chart like:
142+
// import { Chart } from "@esri/cedar";
143+
// if you've loaded the Cedar using script tags
144+
// and are using the cedar global instead
145+
// you should replace this line with:
146+
// var chart = new cedar.Chart(elementId, {"type": "bar"})
147+
var chart = new Chart(elementId, {"type": "bar"})
148+
.datasets(datasets)
149+
.series(series)
150+
.overrides(overrides);
151+
152+
// render the chart
153+
chart.show();
124154
```
125155

126156
See the [API documentation](https://esri.github.io/cedar/api) for further details on how to work with cedar charts.

0 commit comments

Comments
 (0)