@@ -23,16 +23,19 @@ Angular directive for [Apache ECharts (incubating)](https://github.com/apache/in
23
23
- [ Installation] ( #installation )
24
24
- [ Upgrade from v4.x] ( #upgrade-from-v4x )
25
25
- [ Usage] ( #usage )
26
+ - [ Standalone] ( #standalone )
27
+ - [ NgModule] ( #ngmodule )
28
+ - [ Directive] ( #directive )
26
29
- [ API] ( #api )
27
- - [ Directive] ( #directive )
30
+ - [ Directive] ( #directive-1 )
28
31
- [ ECharts API] ( #echarts-api )
29
32
- [ ECharts Instance] ( #echarts-instance )
30
33
- [ ECharts Extensions] ( #echarts-extensions )
31
34
- [ Service] ( #service )
32
35
- [ Events] ( #events )
33
36
- [ Custom Build] ( #custom-build )
34
- - [ Legacy Custom Build] ( #legacy-custom-build )
35
37
- [ Treeshaking Custom Build] ( #treeshaking-custom-build )
38
+ - [ Legacy Custom Build] ( #legacy-custom-build )
36
39
- [ Custom Locale] ( #custom-locale )
37
40
- [ Demo] ( #demo )
38
41
@@ -42,7 +45,7 @@ Angular directive for [Apache ECharts (incubating)](https://github.com/apache/in
42
45
43
46
Latest version @npm :
44
47
45
- - ` v16.1.2 ` for Angular 16
48
+ - ` v16.2.0 ` for Angular 16
46
49
- ` v15.0.3 ` for Angular 15
47
50
- ` v14.0.0 ` for Angular 14
48
51
- ` v8.0.1 ` for Angular 13
@@ -55,6 +58,10 @@ A starter project on Github: https://github.com/xieziyu/ngx-echarts-starter
55
58
56
59
# Latest Update
57
60
61
+ - 2023.10.11: v16.2.0:
62
+
63
+ - Feat: Exported standalone ` NgxEchartsDirective ` , ` provideEcharts ` and ` provideEchartsCore `
64
+
58
65
- 2023.10.11: v16.1.0:
59
66
60
67
- Feat: Add types to ` chartXXX ` EventEmitters. Support new events such as: ` 'selectchanged' `
@@ -93,10 +100,6 @@ A starter project on Github: https://github.com/xieziyu/ngx-echarts-starter
93
100
- Fix: remove @juggle/resize-observer from the peer dependencies
94
101
- Perf: fix performance issue [ #330 ] ( https://github.com/xieziyu/ngx-echarts/issues/330 )
95
102
96
- - 2021.08.05: v7.0.2:
97
-
98
- - [ PR #322 ] ( https://github.com/xieziyu/ngx-echarts/pull/322 ) : Add initOpts locale property (by [ augustoicaro] ( https://github.com/augustoicaro ) )
99
-
100
103
- 2021.05.17: v7.0.0:
101
104
102
105
- Feat: support Angular v11, ECharts v5
@@ -167,107 +170,105 @@ A starter project on Github: https://github.com/xieziyu/ngx-echarts-starter
167
170
168
171
Please refer to the [ demo] ( https://xieziyu.github.io/ngx-echarts ) page.
169
172
170
- 1 . Firstly, import ` NgxEchartsModule ` in your app module (or any other proper angular module):
171
-
172
- ``` typescript
173
- import { NgxEchartsModule } from ' ngx-echarts' ;
174
-
175
- @NgModule ({
176
- imports: [
177
- NgxEchartsModule .forRoot ({
178
- /**
179
- * This will import all modules from echarts.
180
- * If you only need custom modules,
181
- * please refer to [Custom Build] section.
182
- */
183
- echarts : () => import (' echarts' ), // or import('./path-to-my-custom-echarts')
184
- }),
185
- ],
186
- })
187
- export class AppModule {}
188
- ```
173
+ ## Standalone
189
174
190
- The echarts library will be imported ** only when it gets called the first time ** thanks to the function that uses the native import .
175
+ import ` NgxEchartsDirective ` and ` provideEcharts ` . Or you can use ` provideEchartsCore ` to do treeshaking custom build .
191
176
192
- You can also directly pass the echarts instead which will slow down initial rendering because it will load the whole echarts into your main bundle.
177
+ ``` typescript
178
+ import { NgxEchartsDirective , provideEcharts } from ' ngx-echarts' ;
179
+
180
+ @Component ({
181
+ selector: ' app-root' ,
182
+ standalone: true ,
183
+ imports: [CommonModule , NgxEchartsDirective ],
184
+ templateUrl: ' ./app.component.html' ,
185
+ styleUrls: [' ./app.component.scss' ],
186
+ providers: [
187
+ provideEcharts (),
188
+ ]
189
+ })
190
+ export class AppComponent {}
191
+ ```
193
192
194
- ``` typescript
195
- import * as echarts from ' echarts' ;
196
- import { NgxEchartsModule } from ' ngx-echarts' ;
193
+ ## NgModule
197
194
198
- @NgModule ({
199
- imports: [
200
- NgxEchartsModule .forRoot ({ echarts }),
201
- ],
202
- })
203
- export class AppModule {}
204
- ```
195
+ import ` NgxEchartsModule ` :
205
196
206
- When using NgxEchartsModule in a ** standalone component** , we can use token ` NGX_ECHARTS_CONFIG ` to provide echarts
207
-
208
- ``` typescript
209
- import { NgxEchartsModule , NGX_ECHARTS_CONFIG } from ' ngx-echarts' ;
210
-
211
- @Component ({
212
- standalone: true ,
213
- selector: ' my-chart' ,
214
- template: `
215
- <div echarts [options]="chartOptions" class="demo-chart"></div>
216
- ` ,
217
- imports: [NgxEchartsModule ],
218
- providers: [
219
- {
220
- provide: NGX_ECHARTS_CONFIG ,
221
- useFactory : () => ({ echarts : () => import (' echarts' ) })
222
- },
223
- ]
224
- })
225
- export class MyChartComponent {
226
- // logic
227
- }
228
- ```
197
+ ``` typescript
198
+ import { NgxEchartsModule } from ' ngx-echarts' ;
229
199
230
- 2 . Then: use ` echarts ` directive in a div which has ** pre-defined height** . (From v2.0, it has default height: 400px)
200
+ @NgModule ({
201
+ imports: [
202
+ NgxEchartsModule .forRoot ({
203
+ /**
204
+ * This will import all modules from echarts.
205
+ * If you only need custom modules,
206
+ * please refer to [Custom Build] section.
207
+ */
208
+ echarts : () => import (' echarts' ), // or import('./path-to-my-custom-echarts')
209
+ }),
210
+ ],
211
+ })
212
+ export class AppModule {}
213
+ ```
214
+
215
+ The echarts library will be imported ** only when it gets called the first time** thanks to the function that uses the native import.
216
+
217
+ You can also directly pass the echarts instead which will slow down initial rendering because it will load the whole echarts into your main bundle.
218
+
219
+ ``` typescript
220
+ import * as echarts from ' echarts' ;
221
+ import { NgxEchartsModule } from ' ngx-echarts' ;
231
222
232
- - Simple example:
223
+ @NgModule ({
224
+ imports: [
225
+ NgxEchartsModule .forRoot ({ echarts }),
226
+ ],
227
+ })
228
+ export class AppModule {}
229
+ ```
233
230
234
- - html:
231
+ ## Directive
235
232
236
- ``` html
237
- <div echarts [options] =" chartOption" class =" demo-chart" ></div >
238
- ```
233
+ use ` echarts ` directive in a div which has ** pre-defined height** . (From v2.0, it has default height: 400px)
239
234
240
- - scss :
235
+ - html :
241
236
242
- ```css
243
- .demo-chart {
244
- height: 400px;
245
- }
246
- ```
237
+ ``` html
238
+ <div echarts [options] =" chartOption" class =" demo-chart" ></div >
239
+ ```
247
240
248
- - component :
241
+ - css :
249
242
250
- ```typescript
251
- import { EChartsOption } from 'echarts';
243
+ ``` css
244
+ .demo-chart {
245
+ height : 400px ;
246
+ }
247
+ ```
252
248
253
- // ...
249
+ - component:
254
250
255
- chartOption: EChartsOption = {
256
- xAxis: {
257
- type: 'category',
258
- data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
259
- },
260
- yAxis: {
261
- type: 'value',
262
- },
263
- series: [
264
- {
265
- data: [820, 932, 901, 934, 1290, 1330, 1320],
266
- type: 'line',
267
- },
268
- ],
269
- };
270
- ```
251
+ ``` typescript
252
+ import { EChartsOption } from ' echarts' ;
253
+
254
+ // ...
255
+
256
+ chartOption : EChartsOption = {
257
+ xAxis: {
258
+ type: ' category' ,
259
+ data: [' Mon' , ' Tue' , ' Wed' , ' Thu' , ' Fri' , ' Sat' , ' Sun' ],
260
+ },
261
+ yAxis: {
262
+ type: ' value' ,
263
+ },
264
+ series: [
265
+ {
266
+ data: [820 , 932 , 901 , 934 , 1290 , 1330 , 1320 ],
267
+ type: ' line' ,
268
+ },
269
+ ],
270
+ };
271
+ ```
271
272
272
273
# API
273
274
@@ -408,6 +409,76 @@ You can refer to the ECharts tutorial: [Events and Actions in ECharts](https://e
408
409
409
410
# Custom Build
410
411
412
+ ## Treeshaking Custom Build
413
+
414
+ > Since version 5.0.1 ECharts supports [ Treeshaking with NPM] ( https://echarts.apache.org/en/tutorial.html#Use%20ECharts%20with%20bundler%20and%20NPM ) .
415
+
416
+ The ` app.modules.ts ` should look like this:
417
+
418
+ ``` typescript
419
+ import { BrowserModule } from ' @angular/platform-browser' ;
420
+ import { NgModule } from ' @angular/core' ;
421
+ import { HttpClientModule } from ' @angular/common/http' ;
422
+
423
+ import { NgxEchartsDirective , provideEchartsCore } from ' ngx-echarts' ;
424
+
425
+ import { AppComponent } from ' ./app.component' ;
426
+
427
+ // Import the echarts core module, which provides the necessary interfaces for using echarts.
428
+ import * as echarts from ' echarts/core' ;
429
+
430
+ // Import bar charts, all suffixed with Chart
431
+ import { BarChart } from ' echarts/charts' ;
432
+
433
+ // Import the tooltip, title, rectangular coordinate system, dataset and transform components
434
+ import {
435
+ TitleComponent ,
436
+ TooltipComponent ,
437
+ GridComponent ,
438
+ DatasetComponent ,
439
+ TransformComponent
440
+ } from ' echarts/components' ;
441
+
442
+ // Features like Universal Transition and Label Layout
443
+ import { LabelLayout , UniversalTransition } from ' echarts/features' ;
444
+
445
+ // Import the Canvas renderer
446
+ // Note that including the CanvasRenderer or SVGRenderer is a required step
447
+ import { CanvasRenderer } from ' echarts/renderers' ;
448
+
449
+ // Import the theme
450
+ import ' echarts/theme/macarons.js' ;
451
+
452
+ // Register the required components
453
+ echarts .use ([
454
+ BarChart ,
455
+ TitleComponent ,
456
+ TooltipComponent ,
457
+ GridComponent ,
458
+ DatasetComponent ,
459
+ TransformComponent ,
460
+ LabelLayout ,
461
+ UniversalTransition ,
462
+ CanvasRenderer
463
+ ]);
464
+
465
+ @NgModule ({
466
+ declarations: [AppComponent ],
467
+ imports: [
468
+ BrowserModule ,
469
+ HttpClientModule ,
470
+ // import standalone directive:
471
+ NgxEchartsDirective ,
472
+ ],
473
+ providers: [{
474
+ // Provide custom builded ECharts core:
475
+ provideEchartsCore({ echarts })
476
+ }],
477
+ bootstrap: [AppComponent ],
478
+ })
479
+ export class AppModule {}
480
+ ```
481
+
411
482
## Legacy Custom Build
412
483
413
484
> Please refer to [ ECharts Documentation] ( https://echarts.apache.org/en/tutorial.html#Create%20Custom%20Build%20of%20ECharts ) for more details.
@@ -466,41 +537,6 @@ function (root, factory) {
466
537
}
467
538
```
468
539
469
- ## Treeshaking Custom Build
470
-
471
- > Since version 5.0.1 ECharts supports [ Treeshaking with NPM] ( https://echarts.apache.org/en/tutorial.html#Use%20ECharts%20with%20bundler%20and%20NPM ) .
472
-
473
- There is no need for the ` custom-echarts.ts ` file anymore. The ` app.modules.ts ` should look like this:
474
-
475
- ``` typescript
476
- import { BrowserModule } from ' @angular/platform-browser' ;
477
- import { NgModule } from ' @angular/core' ;
478
- import { HttpClientModule } from ' @angular/common/http' ;
479
-
480
- import { NgxEchartsModule } from ' ngx-echarts' ;
481
-
482
- import { AppComponent } from ' ./app.component' ;
483
-
484
- // Import the echarts core module, which provides the necessary interfaces for using echarts.
485
- import * as echarts from ' echarts/core' ;
486
- // Import bar charts, all with Chart suffix
487
- import { BarChart } from ' echarts/charts' ;
488
- import { TitleComponent , TooltipComponent , GridComponent } from ' echarts/components' ;
489
- // Import the Canvas renderer, note that introducing the CanvasRenderer or SVGRenderer is a required step
490
- import { CanvasRenderer } from ' echarts/renderers' ;
491
- import ' echarts/theme/macarons.js' ;
492
-
493
- echarts .use ([TitleComponent , TooltipComponent , GridComponent , BarChart , CanvasRenderer ]);
494
-
495
- @NgModule ({
496
- declarations: [AppComponent ],
497
- imports: [BrowserModule , NgxEchartsModule .forRoot ({ echarts }), HttpClientModule ],
498
- providers: [],
499
- bootstrap: [AppComponent ],
500
- })
501
- export class AppModule {}
502
- ```
503
-
504
540
# Custom Locale
505
541
506
542
You can change the chart locale registering a built-in locale (located in ` node_modules/echarts/lib/i18n/ ` ) or a custom locale object. To register a locale, you will need to change the module that echart is being imported (usually ` app.module.ts ` ).
0 commit comments