echarts
Global echarts object, which can be accessed after including echarts.js
in script tag or through require('echarts')
in AMD environment.
Properties
echarts. init
(dom: HTMLDivElement|HTMLCanvasElement, theme?: Object|string, opts?: {
devicePixelRatio?: number,
renderer?: string,
useDirtyRect?: boolean, // Since `5.0.0`
useCoarsePointer?: boolean, // Since `5.4.0`
pointerSize?: number, // Since `5.4.0`
ssr?: boolean, // Since `5.3.0`
width?: number|string,
height?: number|string,
locale?: string // Since `5.0.0`
}) => ECharts
Creates an ECharts instance, and returns an echartsInstance. You shall not initialize multiple ECharts instances on a single container.
Parameters
dom
Instance container, usually is a DIV element with height and width defined. It's only optional when
opts.ssr
is enabled for server-side rendering.It can also be a
canvas
element. thus the canvas can be used somewhere else as image directly after rendering the chart. For example, canvas can be used as a texture in WebGL, which enables updating charts in real-time, as compared to using images generated with echartsInstance.getDataURL.theme
Theme to be applied. This can be a configuring object of a theme, or a theme name registered through echarts.registerTheme. See Overview of Style Customization.
opts
Optional chart configurations; which may contain:
devicePixelRatio
Ratio of one physical pixel to the size of one device independent pixels. Browser'swindow.devicePixelRatio
is used by default.renderer
Supports'canvas'
or'svg'
. See Render by Canvas or SVG.ssr
Whether to use server-side rendering. Only available in SVG rendering mode. When enabled, it will no longer render automatically every frame, you have to use the renderToSVGString method to get the rendered SVG string. See Server Side Rendering.useDirtyRect
Enable dirty rectangle rendering or not,false
by default. See New features in ECharts 5.useCoarsePointer
Whether to expand the response area when interacting with elements.null
means enabling for mobile devices;true
means always enabling;false
means always disabling. See Coarse Pointer for more information.pointerSize
Size of expanded interaction size in pixels. It should be used along withopts.useCoarsePointer
.width
Specify width explicitly, in pixel. If setting tonull
/undefined
/'auto'
, width ofdom
(instance container) will be used.height
Specify height explicitly, in pixel. If setting tonull
/undefined
/'auto'
, height ofdom
(instance container) will be used.locale
Specify the locale. There are two builtins:'ZH'
and'EN'
. Or you can use echarts.registerLocale to register a new locale. Or supported locales can be referenced in src/i18n.If no need to specify a theme, a
null
should be passed beforeopts
. Example:const chart = echarts.init(dom, null, {renderer: 'svg'});
Note
If DIV is hidden, ECharts initialization tends to fail due to the lack of width and height information. In this case, you can explicitly specify style.width
and style.height
of DIV, or manually call echartsInstance.resize after showing DIV.
The height and width must be set via opts.width
and opts.height
in the server side rendering.
echarts. connect
(group:string|Array)
Connects interaction of multiple chart series.
Parameters
group
Group id, or array of chart instance.
For example:
// set group id of each instance respectively.
chart1.group = 'group1';
chart2.group = 'group1';
echarts.connect('group1');
// or incoming instance array that need to be linked.
echarts.connect([chart1, chart2]);
echarts. disconnect
(group:string)
Disconnects interaction of multiple chart series. To have one single instance to be removed, you can set group
of chart instance to be null.
Parameters
group
group id.
echarts. dispose
(target: ECharts|HTMLDivElement|HTMLCanvasElement)
Destroys chart instance, after which the instance cannot be used any more.
echarts. getInstanceByDom
(target: HTMLDivElement|HTMLCanvasElement) => ECharts
Returns chart instance of dom container.
echarts. use
Since
5.0.1
Use components. Used with the new tree-shaking API.
NOTE: echarts.use
must be used before eharts.init
// Import the echarts core module, which provides the necessary interfaces for using echarts.
import * as echarts from 'echarts/core';
// Import bar charts, all with Chart suffix
import {
BarChart
} from 'echarts/charts';
// import rectangular coordinate system component, all suffixed with Component
import {
GridComponent
} from 'echarts/components';
// Import the Canvas renderer, note that introducing the CanvasRenderer or SVGRenderer is a required step
import {
CanvasRenderer
} from 'echarts/renderers';
// Register the required components
echarts.use(
[GridComponent, BarChart, CanvasRenderer]
);
See Use ECharts with bundler and NPM for more detailed explanation.
echarts. registerMap
(
mapName: string,
opt: {
geoJSON: Object | string;
specialAreas?: Object;
}
)
| (
mapName: string,
opt: {
svg: Object | string;
}
)
| (
mapName: string,
geoJSON: Object | string,
specialAreas?: Object
)
Registers available maps. This can only be used after including geo component or chart series of map.
Please refer to option.geo for usage.
Parameters
mapName
Map name, referring to
map
value set in geo component or map.opt
geoJSON
Optional. Data in GeoJson format. See https://geojson.org/ for more format information. Can be a JSON string or a parsed object. This key can also begeoJson
.svg
Optional. Data in SVG format. Can be a SVG string or a parsed SVG DOM object. See more info in SVG Base Map. Introduced in v5.1.0specialAreas
Optional. zoomed part of a specific area in the map for better visual effect. Only work forgeoJSON
.
For example USA Population Estimates:
echarts.registerMap('USA', usaJson, {
// Move Alaska to the bottom left of United States
Alaska: {
// Upper left longitude
left: -131,
// Upper left latitude
top: 25,
// Range of longitude
width: 15
},
// Hawaii
Hawaii: {
left: -110,
top: 28,
width: 5
},
// Puerto Rico
'Puerto Rico': {
left: -76,
top: 26,
width: 2
}
});
Note:
If you only import the required components in your project, starting from v5.3.0 registerMap
has to be used after the MapChart
or GeoComponent
is imported.
echarts. getMap
(mapName: string)
Get a registered map in the following format:
{
// geoJSON data of the map
geoJSON: Object,
// special area, see registerMap() for more information
specialAreas: Object
}
Note:
geoJSON
can also begeoJson
, they have the same reference.- SVG registered by
registerMap
can not be obtained by this method yet. - If you only import the required components in your project, starting from v5.3.0
getMap
has to be used after theMapChart
orGeoComponent
is imported.
echarts. registerTheme
(themeName: string, theme: Object)
Registers a theme, should be specified when initialize the chart instance.
echarts. registerLocale
Since
5.0.0
(locale: string, localeCfg: Object)
Registers a locale, should be specified when initialize the chart instance. See the format in src/i18n/langEN.ts
echarts. setPlatformAPI
Since
5.3.0
(platformAPI?: {
createCanvas(): HTMLCanvasElement
measureText(text: string, font?: string): { width: number }
loadImage(
src: string,
onload: () => void,
onerror: () => void
): HTMLImageElement
}) => void
Sets the platform-related API, which may need to be provided when non-browser platforms such as NodeJS.
createCanvas
Creates a Canvas element, mainly used for measuring text width, which is required whenmeasureText
is not provided.measureText
measures the width of the text. By default will use the interface provided by the Canvas element to measure the width of the text. It can be replaced with a lighter implementation.loadImage
Load image, required when using Canvas rendering mode and using URLs as images.
echarts. graphic
Util methods about graphics.
echarts.graphic. extendShape
Create a new shape class.
(
opts: Object
) => zrender.graphic.Path
The details of the parameter opts
can be checked in zrender.graphic.Path
echarts.graphic. registerShape
Register a user defined shape.
(
name: string,
ShapeClass: zrender.graphic.Path
)
The ShapeClass
should be generated by echarts.graphic.extendShape.
Then the shape class can be fetched by echarts.graphic.getShapeClass
registerShape
will overwrite the registered shapes, including the registered built-in shapes, if using the same name
.
The registered shapes can be used in custom series and
graphic component by declaring {type: name}
.
For example:
var MyShape = echarts.graphic.extendShape({
shape: {
x: 0,
y: 0,
width: 0,
height: 0
},
buildPath: function (ctx, shape) {
ctx.moveTo(shape.x, shape.y);
ctx.lineTo(shape.x + shape.width, shape.y);
ctx.lineTo(shape.x, shape.y + shape.height);
ctx.lineTo(shape.x + shape.width, shape.y + shape.height);
ctx.closePath();
}
});
echarts.graphic.registerShape('myCustomShape', MyShape);
var option = {
series: {
type: 'custom',
coordinateSystem: 'none',
renderItem: function (params, api) {
return {
type: 'myCustomShape',
shape: {
x: api.value(0),
y: api.value(1),
width: api.value(2),
height: api.value(3)
},
style: {
fill: 'red'
}
};
},
data: [[10, 20, 30, 40]]
}
};
echarts.graphic. getShapeClass
Get the registered shape class.
(
name: String
) => zrender.graphic.Path
Some built-in shapes are registered by default:
'circle'
, 'sector'
, 'ring'
, 'polygon'
, 'polyline'
, 'rect'
, 'line'
, 'bezierCurve'
, 'arc'
.
echarts.graphic. clipPointsByRect
Clip the given points by the given rectangular.
(
// The points to be clipped, like [[23, 44], [12, 15], ...].
points: Array.<Array.<number>>,
// The rectangular that is used to clip points.
rect: {
x: number,
y: number,
width: number,
height: number
}
) => Array.<Array.<number>> // The result Points.
echarts.graphic. clipRectByRect
Clip the first input rectangular by the second input rectangular.
(
// The rectangular to be clipped.
targetRect: {
x: number,
y: number,
width: number,
height: number
},
// The rectangular that is used to clip the first rectangular.
rect: {
x: number,
y: number,
width: number,
height: number
}
) => { // The result rectangular.
x: number,
y: number,
width: number,
height: number
}
Notice: if the rect is totally clipped, returns undefined
.