Skip to content

AngularJS echarts.init & Option API

AngularJS (1.x) 核心 API —— 带控制器/服务/指令的模块定义、$scope 摘要循环,以及用于 XHR 的 $http。

2 classes · 9 methods

module

5 methods

angular.module 用于定义应用模块,及其控制器、服务和指令注册。

echarts.init(dom, theme?, opts?) -> ECharts

模块的 getter/setter。带 requires 创建新模块;不带 requires 获取现有模块。

Parameters

NameTypeDescription
domHTMLElementContainer element.
themestring | objectOptional registered theme name or theme object.
optsobjectOptional { 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

NameTypeDescription
optionEChartsOptionConfiguration object: series, xAxis, yAxis, tooltip, legend, etc.
optsobjectOptional { 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

NameTypeDescription
optsobjectOptional { 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

NameTypeDescription
typestringSeries type: 'bar', 'line', 'pie', 'scatter', 'radar', etc.
dataArrayData 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

NameTypeDescription
typestring'category' | 'value' | 'time' | 'log'.
dataArrayCategory labels (for type 'category').

Returns

option

Example

echarts
xAxis: {
  type: 'category',
  data: ['Mon', 'Tue', 'Wed', 'Thu'],
}
yAxis: { type }

监听在 scope 层级上广播($broadcast)或冒泡($emit)的事件。

Parameters

NameTypeDescription
typestring'value' | 'category' | 'time' | 'log'.

Returns

option

Example

echarts
yAxis: { type: 'value', min: 0, max: 100 }
tooltip: { trigger, formatter }

向所有子 scope(及其子级)向下分发事件。

Parameters

NameTypeDescription
triggerstring'item' | 'axis' | 'none'.
formatterstring | FunctionString template or callback (params) => string.

Returns

option

Example

echarts
tooltip: {
  trigger: 'axis',
  formatter: '{b}: {c}',
}