module
5 methodsangular.module 用于定义应用模块,及其控制器、服务和指令注册。
echarts.init(dom, theme?, opts?) -> ECharts模块的 getter/setter。带 requires 创建新模块;不带 requires 获取现有模块。
Parameters
| Name | Type | Description |
|---|---|---|
| dom | HTMLElement | Container element. |
| theme | string | object | Optional registered theme name or theme object. |
| opts | object | Optional { renderer: 'canvas' | 'svg', width, height, locale }. |
Returns
ECharts
Example
echarts
import * as echarts from 'echarts';
const chart = echarts.init(document.getElementById('main'), null, {
renderer: 'canvas',
});chart.setOption(option, opts?)在模块上注册控制器构造函数;通过参数名或 $inject 注解注入依赖。
Parameters
| Name | Type | Description |
|---|---|---|
| option | EChartsOption | Configuration object: series, xAxis, yAxis, tooltip, legend, etc. |
| opts | object | Optional { notMerge, lazyUpdate, silent }. |
Returns
void
Example
echarts
chart.setOption({
xAxis: { type: 'category', data: ['Mon', 'Tue'] },
yAxis: { type: 'value' },
series: [{ type: 'bar', data: [10, 20] }],
});chart.getOption() -> EChartsOption注册用 new 实例化的单例服务;通过构造函数注入依赖。
Returns
EChartsOption
Example
echarts
const current = chart.getOption();
console.log(current.series);chart.resize(opts?)使用工厂函数注册指令,返回指令定义对象(DDO)。
Parameters
| Name | Type | Description |
|---|---|---|
| opts | object | Optional { width, height, silent }. |
Returns
void
Example
echarts
window.addEventListener('resize', () => chart.resize());chart.dispose()Disposes the chart instance, releasing resources and removing the DOM it created.
Returns
void
Example
echarts
chart.dispose();$scope
4 methods$scope 对象 —— 控制器和视图之间的粘合剂 —— 及其摘要循环方法。
series: [{ type, data, ... }]注册监听器回调,在摘要循环中监视的表达式变化时调用。
Parameters
| Name | Type | Description |
|---|---|---|
| type | string | Series type: 'bar', 'line', 'pie', 'scatter', 'radar', etc. |
| data | Array | Data values; numbers, [value] pairs, or objects. |
Returns
option
Example
echarts
series: [
{ type: 'bar', data: [5, 20, 36, 10] },
{ type: 'line', data: [15, 12, 30, 20] },
]xAxis: { type, data }手动触发摘要循环,计算 expr 并将变化传播给监听器。在非 AngularJS 代码中更新 scope 时使用。
Parameters
| Name | Type | Description |
|---|---|---|
| type | string | 'category' | 'value' | 'time' | 'log'. |
| data | Array | Category labels (for type 'category'). |
Returns
option
Example
echarts
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu'],
}yAxis: { type }监听在 scope 层级上广播($broadcast)或冒泡($emit)的事件。
Parameters
| Name | Type | Description |
|---|---|---|
| type | string | 'value' | 'category' | 'time' | 'log'. |
Returns
option
Example
echarts
yAxis: { type: 'value', min: 0, max: 100 }tooltip: { trigger, formatter }向所有子 scope(及其子级)向下分发事件。
Parameters
| Name | Type | Description |
|---|---|---|
| trigger | string | 'item' | 'axis' | 'none'. |
| formatter | string | Function | String template or callback (params) => string. |
Returns
option
Example
echarts
tooltip: {
trigger: 'axis',
formatter: '{b}: {c}',
}