ECharts Installation
1. Standalone Version
We can directly download echarts.min.js and use Import via tag.
In addition, in a development environment you can use the source-code version of echarts.js and Import via tag; the source version includes common error prompts and warnings.
We can also directly download more feature-rich versions from the official ECharts website, including different themes and languages. Download address:https://echarts.apache.org/zh/download.html。
These pre-built echarts provide the following customizations:
- Full version:
echarts/dist/echarts.js, the largest in size, containing all charts and components; see the included contents at:echarts/echarts.all.js。 - Common version:
echarts/dist/echarts.common.js, moderate in size, containing common charts and components; see the included contents at:echarts/echarts.common.js。 - Simplified version:
echarts/dist/echarts.simple.js, smaller in size, containing only the most commonly used charts and components; see the included contents at:echarts/echarts.simple.js。
2. Using the CDN method
The following recommends two relatively stable foreign CDNs; no good domestic one has been found yet, so it is still recommended to download locally.
-
Staticfile CDN (China) : https://cdn.staticfile.net/echarts/4.3.0/echarts.min.js
-
jsDelivr:https://cdn.jsdelivr.net/npm/echarts@4.3.0/dist/echarts.min.js。
-
cdnjs : https://cdnjs.cloudflare.com/ajax/libs/echarts/4.3.0/echarts.min.js
Staticfile CDN (China)
<div id="main" style=">width: 600px;height:400px;
"
</
div
Try it »
jsDelivr
<div id="main" style=">width: 600px;height:400px;
"
</
div
Try it »
cdnjs
<div id="main" style=">width: 600px;height:400px;
"
</
div
Try it »
3. NPM method
Because npm installation is slow, this tutorial uses the Taobao mirror and its command cnpm; for installation instructions, refer to:Use the Taobao NPM mirror。
The npm version needs to be greater than 3.0; if it is lower than this version, you need to upgrade it:
# Check version
$ npm -v
2.3.0
#升级 npm
cnpm install npm -g
# Upgrade or install cnpm
npm install cnpm -g
Get echarts via cnpm:
# Latest stable version
$ cnpm install echarts --save
After installation, ECharts and zrender will be placed in the node_modules directory, so we can use them directly in project code with require('echarts').
Example
var
echarts
=
require
(
'
echarts
'
)
;
//
Initialize the echarts instance based on the prepared dom
var
myChart
=
echarts
.
init
(
document
.
getElementById
(
'
main
'
)
)
;
//
Drawing charts
myChart
.
setOption
(
{
title
:
{
text
:
'
ECharts Getting Started Example
'
}
,
tooltip
:
{
}
,
xAxis
:
{
data
:
[
'
Shirt
'
,
'
Wool sweater
'
,
'
Chiffon Blouse
'
,
'
Pants
'
,
'
High heels
'
,
'
Socks
'
]
}
,
yAxis
:
{
}
,
series
:
[
{
name
:
'
Sales
'
,
type
:
'
bar
'
,
data
:
[
5
,
20
,
36
,
10
,
10
,
20
]
}
]
}
)
;