Gathering detailed insights and metrics for ngx-echarts
Gathering detailed insights and metrics for ngx-echarts
Gathering detailed insights and metrics for ngx-echarts
Gathering detailed insights and metrics for ngx-echarts
An angular (ver >= 2.x) directive for ECharts (ver >= 3.x)
npm install ngx-echarts
83.3
Supply Chain
99.1
Quality
77.8
Maintenance
100
Vulnerability
98.2
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,113 Stars
206 Commits
198 Forks
35 Watching
13 Branches
29 Contributors
Updated on 25 Nov 2024
TypeScript (76.69%)
HTML (14.29%)
JavaScript (4.82%)
CSS (2.46%)
SCSS (1.74%)
Cumulative downloads
Total Downloads
Last day
13.8%
20,658
Compared to previous day
Last week
6.6%
100,763
Compared to previous week
Last month
0.6%
423,252
Compared to previous month
Last year
31.6%
4,363,872
Compared to previous year
ngx-echarts
is an Angular (ver >= 2.x) directive for ECharts (ver >= 3.x).
Latest version @npm:
v18.0.0
for Angular 18v17.2.0
for Angular 17v16.2.0
for Angular 16v15.0.3
for Angular 15v14.0.0
for Angular 14v8.0.1
for Angular 13v7.1.0
for Angular >= 11, < 13v6.0.1
for Angular >= 10, < 11v5.2.2
for Angular >= 6, < 10v2.3.1
for Angular < 6 (Please refer to https://github.com/xieziyu/ngx-echarts/blob/v2.x/README.md)A starter project on Github: https://github.com/xieziyu/ngx-echarts-starter
Since v5.0
1# if you use npm 2npm install echarts -S 3npm install ngx-echarts -S 4 5# or if you use yarn 6yarn add echarts 7yarn add ngx-echarts
If you need ECharts GL support, please install it first:
1npm install echarts-gl -S 2 3# or 4yarn add echarts-gl
Import other extensions such as themes or echarts-gl
in your main.ts
: ECharts Extensions
echarts
and provide it in NgxEchartsModule.forRoot({ echarts })
.NgxEchartsCoreModule
is removed.Please refer to the demo page.
import NgxEchartsDirective
and provideEcharts
. Or you can use provideEchartsCore
to do treeshaking custom build.
1import { NgxEchartsDirective, provideEcharts } from 'ngx-echarts'; 2 3@Component({ 4 selector: 'app-root', 5 standalone: true, 6 imports: [CommonModule, NgxEchartsDirective], 7 templateUrl: './app.component.html', 8 styleUrls: ['./app.component.scss'], 9 providers: [ 10 provideEcharts(), 11 ] 12}) 13export class AppComponent {}
import NgxEchartsModule
:
1import { NgxEchartsModule } from 'ngx-echarts'; 2 3@NgModule({ 4 imports: [ 5 NgxEchartsModule.forRoot({ 6 /** 7 * This will import all modules from echarts. 8 * If you only need custom modules, 9 * please refer to [Custom Build] section. 10 */ 11 echarts: () => import('echarts'), // or import('./path-to-my-custom-echarts') 12 }), 13 ], 14}) 15export class AppModule {}
The echarts library will be imported only when it gets called the first time thanks to the function that uses the native import.
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.
1import * as echarts from 'echarts'; 2import { NgxEchartsModule } from 'ngx-echarts'; 3 4@NgModule({ 5 imports: [ 6 NgxEchartsModule.forRoot({ echarts }), 7 ], 8}) 9export class AppModule {}
use echarts
directive in a div which has pre-defined height. (From v2.0, it has default height: 400px)
1<div echarts [options]="chartOption" class="demo-chart"></div>
1.demo-chart { 2 height: 400px; 3}
1import { EChartsOption } from 'echarts'; 2 3// ... 4 5chartOption: EChartsOption = { 6 xAxis: { 7 type: 'category', 8 data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], 9 }, 10 yAxis: { 11 type: 'value', 12 }, 13 series: [ 14 { 15 data: [820, 932, 901, 934, 1290, 1330, 1320], 16 type: 'line', 17 }, 18 ], 19};
echarts
directive support following input properties:
Input | Type | Default | Description |
---|---|---|---|
[options] | object | null | The same as the options on the official demo site. |
[merge] | object | null | Used to update a part of the options , especially helpful when you need to update the chart data. In fact, the value of merge will be used in echartsInstance.setOption() with notMerge = false . Refer to ECharts documentation for details. |
[loading] | boolean | false | Used to toggle the echarts loading animation when your data is not ready. |
[autoResize] | boolean | true | If set to true , the chart will be automatically resized when the window's width is changed. |
[initOpts] | object | null | The value of [initOpts] will be used in echarts.init() . It may contain devicePixelRatio , renderer , width or height properties. Refer to ECharts documentation for details. |
[theme] | string | null | Used it to initialize echarts with theme. The theme file must also be imported in main.ts . |
[loadingOpts] | object | null | Input an object to customize the loading style. Refer to ECharts documentation for details. |
By default, loadingOpts
is:
1{ 2 text: 'loading', 3 color: '#c23531', 4 textColor: '#000', 5 maskColor: 'rgba(255, 255, 255, 0.8)', 6 zlevel: 0 7}
If you need to access parts of the ECharts API such as echarts.graphic
, please import it from echarts. For example:
1import { graphic } from 'echarts'; 2 3new graphic.LinearGradient(/* ... */);
echartsInstance
is exposed (since v1.1.6) in the (chartInit)
event, enabling you to directly call functions like: resize()
, showLoading()
, etc. For example:
1<div echarts class="demo-chart" [options]="chartOptions" (chartInit)="onChartInit($event)"></div>
1onChartInit(ec) { 2 this.echartsInstance = ec; 3} 4 5resizeChart() { 6 if (this.echartsInstance) { 7 this.echartsInstance.resize(); 8 } 9}
Import echarts theme files or other extension files after you have imported echarts
core. For example:
1import * as echarts from 'echarts'; 2 3/** echarts extensions: */ 4import 'echarts-gl'; 5import 'echarts/theme/macarons.js'; 6import 'echarts/dist/extension/bmap.min.js';
NgxEchartsService
has been obsolete since v4.0
As ECharts supports the 'click'
, 'dblclick'
, 'mousedown'
, 'mouseup'
, 'mouseover'
, 'mouseout'
, and 'globalout'
mouse events, our ngx-echarts
directive also supports the same mouse events but with an additional chart
prefix. For example:
1<div echarts class="demo-chart" [options]="chartOptions" (chartClick)="onChartClick($event)"></div>
It supports following event outputs:
@Output | Event |
---|---|
chartInit | Emitted when the chart is initialized |
chartClick | echarts event: 'click' |
chartDblClick | echarts event: 'dblclick' |
chartMouseDown | echarts event: 'mousedown' |
chartMouseMove | echarts event: 'mousemove' |
chartMouseUp | echarts event: 'mouseup' |
chartMouseOver | echarts event: 'mouseover' |
chartMouseOut | echarts event: 'mouseout' |
chartGlobalOut | echarts event: 'globalout' |
chartContextMenu | echarts event: 'contextmenu' |
chartHighlight | echarts event: 'highlight' |
chartDownplay | echarts event: 'downplay' |
chartSelectChanged | echarts event: 'selectchanged' |
chartLegendSelectChanged | echarts event: 'legendselectchanged' |
chartLegendSelected | echarts event: 'legendselected' |
chartLegendUnselected | echarts event: 'legendunselected' |
chartLegendLegendSelectAll | echarts event: 'legendselectall' |
chartLegendLegendInverseSelect | echarts event: 'legendinverseselect' |
chartLegendScroll | echarts event: 'legendscroll' |
chartDataZoom | echarts event: 'datazoom' |
chartDataRangeSelected | echarts event: 'datarangeselected' |
chartGraphRoam | echarts event: 'graphroam' |
chartGeoRoam | echarts event: 'georoam' |
chartTreeRoam | echarts event: 'treeroam' |
chartTimelineChanged | echarts event: 'timelinechanged' |
chartTimelinePlayChanged | echarts event: 'timelineplaychanged' |
chartRestore | echarts event: 'restore' |
chartDataViewChanged | echarts event: 'dataviewchanged' |
chartMagicTypeChanged | echarts event: 'magictypechanged' |
chartGeoSelectChanged | echarts event: 'geoselectchanged' |
chartGeoSelected | echarts event: 'geoselected' |
chartGeoUnselected | echarts event: 'geounselected' |
chartAxisAreaSelected | echarts event: 'axisareaselected' |
chartBrush | echarts event: 'brush' |
chartBrushEnd | echarts event: 'brushend' |
chartBrushSelected | echarts event: 'brushselected' |
chartGlobalCursorTaken | echarts event: 'globalcursortaken' |
chartRendered | echarts event: 'rendered' |
chartFinished | echarts event: 'finished' |
You can refer to the ECharts tutorial: Events and Actions in ECharts for more details of the event params. You can also refer to the demo page for a detailed example.
Since version 5.0.1 ECharts supports Treeshaking with NPM.
The app.modules.ts
should look like this:
1import { BrowserModule } from '@angular/platform-browser'; 2import { NgModule } from '@angular/core'; 3import { HttpClientModule } from '@angular/common/http'; 4 5import { NgxEchartsDirective, provideEchartsCore } from 'ngx-echarts'; 6 7import { AppComponent } from './app.component'; 8 9// Import the echarts core module, which provides the necessary interfaces for using echarts. 10import * as echarts from 'echarts/core'; 11 12// Import bar charts, all suffixed with Chart 13import { BarChart } from 'echarts/charts'; 14 15// Import the tooltip, title, rectangular coordinate system, dataset and transform components 16import { 17 TitleComponent, 18 TooltipComponent, 19 GridComponent, 20 DatasetComponent, 21 TransformComponent 22} from 'echarts/components'; 23 24// Features like Universal Transition and Label Layout 25import { LabelLayout, UniversalTransition } from 'echarts/features'; 26 27// Import the Canvas renderer 28// Note that including the CanvasRenderer or SVGRenderer is a required step 29import { CanvasRenderer } from 'echarts/renderers'; 30 31// Import the theme 32import 'echarts/theme/macarons.js'; 33 34// Register the required components 35echarts.use([ 36 BarChart, 37 TitleComponent, 38 TooltipComponent, 39 GridComponent, 40 DatasetComponent, 41 TransformComponent, 42 LabelLayout, 43 UniversalTransition, 44 CanvasRenderer 45]); 46 47@NgModule({ 48 declarations: [AppComponent], 49 imports: [ 50 BrowserModule, 51 HttpClientModule, 52 // import standalone directive: 53 NgxEchartsDirective, 54 ], 55 providers: [{ 56 // Provide custom builded ECharts core: 57 provideEchartsCore({ echarts }) 58 }], 59 bootstrap: [AppComponent], 60}) 61export class AppModule {}
Please refer to ECharts Documentation for more details.
If you want to produce a custom build of ECharts, prepare a file like custom-echarts.ts
:
1// custom-echarts.ts 2export * from 'echarts/src/echarts'; 3 4import 'echarts/src/chart/line'; 5import 'echarts/src/chart/bar'; 6// component examples: 7import 'echarts/src/component/tooltip'; 8import 'echarts/src/component/title'; 9import 'echarts/src/component/toolbox';
And then inject it in your NgxEchartsModule
:
1import { NgxEchartsModule } from 'ngx-echarts'; 2import * as echarts from './custom-echarts'; 3 4@NgModule({ 5 imports: [ 6 NgxEchartsModule.forRoot({ 7 echarts, 8 }), 9 ], 10}) 11export class AppModule {}
And if you want to use the global echarts
object, please import it from lib
or src
instead:
1import * as echarts from 'echarts/lib/echarts';
If you need to import theme files, remember to change the 'echarts'
path to 'echarts/lib/echarts'
, for example:
1// ... part of echarts/theme/dark.js: 2function (root, factory) { 3 if (typeof define === 'function' && define.amd) { 4 // AMD. Register as an anonymous module. 5 define(['exports', 'echarts/lib/echarts'], factory); 6 } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') { 7 // CommonJS 8 factory(exports, require('echarts/lib/echarts')); 9 } else { 10 // Browser globals 11 factory({}, root.echarts); 12 } 13}
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
).
1import {NgxEchartsModule} from "ngx-echarts"; 2import * as echarts from 'echarts/core'; 3import langCZ from 'echarts/lib/i18n/langCZ'; 4 5echarts.registerLocale("CZ", langCZ) 6 7@NgModule({ 8 imports: [NgxEchartsModule.forRoot({echarts})], 9 declarations: [], 10 providers: [], 11 bootstrap: [AppComponent] 12})
and in your HTML file use:
1<div echarts [initOpts]="{ locale: 'CZ' }" [options]="options" class="demo-chart"></div>
You can clone this repo to your working copy and then launch the demo page in your local machine:
1npm install 2npm run demo 3 4# or 5yarn install 6yarn demo
The demo page server is listening on: http://localhost:4202
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 2/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
41 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More