ECharts dataset:行列、encode及图表联动
保留二维数组、对象数组、双网格、显式编码、四视图、视觉映射及联动实例。
学完这一章,你能够
- 保留二维数组、对象数组、双网格、显式编码、四视图、视觉映射及联动实例。
- 保留二维数组、对象数组、双网格、显式编码、四视图、视觉映射及联动实例。
数据与图形配置分开
dataset.source可用带表头的二维数组,或带dimensions的对象数组。显式写清sourceHeader和维度顺序更易核对;默认编码取决于轴、系列及布局,不能把第一列永远理解为x坐标。
seriesLayoutBy默认column,row表示按行形成系列。本例双网格保留三行对应三个系列、四个数值列对应四个系列的对照,轴和grid索引也显式绑定。
encode的完整职责
encode可以用维度名或从0开始的索引,可为单项或数组。x/y映射直角轴,tooltip决定提示维度,seriesName组合系列名,itemId提供更新标识,itemName给数据名。
single对应单轴,radius/angle对应极坐标;geo坐标维度为lng/lat,可用encode指定经纬维度,还需注册底图、设置geo并选择对应系列;本组未把地理底图运行列为已验。无坐标系的饼图等用value映射数值。表中保留旧提法和现代条件,不静默删除。
一份数据的多个视图
同一份五维虚构数据可配置四个散点网格,分别比较收入/寿命、地区/收入、收入/人口、寿命/人口。这里保留数据映射教学目标,不把虚构数据当真实国家统计或原始数据采集成功。
水平柱形可把amount编码到x、product编码到y,并用score的视觉映射调颜色。坐标映射与颜色映射是不同通道,不能用一个取代另一个。
联动要观察真实事件
多条折线和饼图共享dataset:updateAxisPointer取得类别索引后选择相应维度,按稳定pie id更新encode和标签。必须检查axesInfo存在及索引范围,不能假定每次事件都有轴数据。
本例提供真实指针动作及可操作的列选择按钮,检查饼图实际读取的新列和图形变化。按钮和事件是两条入口,不能只修改文字制造联动结果。
配置与生命周期参考
| API/字段 | 输入与用途 | 返回/条件 |
| echarts.init(dom,theme,opts) | 有尺寸的DOM、主题和renderer等 | ECharts实例;主题先注册,渲染器先引入 |
| setOption(option,opts) | 普通或复合选项 | void;默认合并,notMerge/replaceMerge按目标设置 |
| getOption() | 读取合并状态 | 配置对象;含默认值,不宜随意整体写回 |
| resize(opts) | width/height等对象 | void;不是resize(宽,高)两个数 |
| on / off | 事件名、可选query及handler | 按事件接口注册/解绑,同函数引用 |
| dispatchAction(payload) | 动作type及目标字段 | 动作及事件不是鼠标回调一一映射 |
| showLoading / hideLoading | 加载状态及可选配置 | 网络成功失败取消都须对应处理 |
| dispose / isDisposed | 释放与状态 | 销毁后不能被旧异步结果更新 |
| getInstanceByDom | 已初始化容器 | 实例或undefined |
| convertToPixel / convertFromPixel | 坐标查询与数值 | 需匹配实际坐标系和系列 |
| title / tooltip / legend | 标题、细节、系列选择 | 名称及所属系列对应 |
| xAxis / yAxis / series | 轴与数据系列 | 类型、单位、索引均明确 |
本章字段及全部分支
| 字段 | 类型/用途 | 条件 |
| dataset.source | 二维表/对象数组 | 明确维度/表头 |
| dimensions / sourceHeader | 顺序、类型/表头 | 默认识别不是所有格式相同 |
| seriesLayoutBy | column默认 / row | 行列对应系列不同 |
| encode.x / y | 维度名或0基索引,可数组 | 实际轴类型对应 |
| tooltip / seriesName | 提示/系列名维度 | 可以多个 |
| itemId / itemName | 更新标识/数据名 | 不是索引和系列id混用 |
| single | 单轴维度 | 需要singleAxis体系 |
| radius / angle | 极坐标维度 | 对应polar体系 |
| lng / lat | geo经纬维度 | 注册底图、geo及相应系列;此组地理运行未验 |
| value | 非坐标系列数值 | 如pie等 |
| gridIndex / xAxisIndex / yAxisIndex | 多网格/多轴 | 分别绑定,均0基 |
| updateAxisPointer | 轴事件索引到数据列 | 检查axesInfo及范围 |
| linked-pie id | 稳定饼图目标 | 四条线、六个数值期,实际换列 |
本章独立核心源码与验证步骤
展开查看收起
import * as echarts from 'echarts';
import {mount} from './lab.js';
// 本章独立配置和实际运行共用;数值均为自有虚构数据。
const specification = {
"key": "echarts-dataset",
"title": "ECharts dataset:行列、encode及图表联动",
"cases": [
{
"id": "dataset-matrix",
"title": "二维数组三系列",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期"
],
[
"HTML",
12,
24,
18
],
[
"CSS",
16,
22,
29
],
[
"JavaScript",
21,
17,
34
],
[
"Web项目",
15,
26,
32
]
]
},
"grid": {
"top": 65,
"bottom": 70,
"containLabel": true
},
"xAxis": {
"type": "category"
},
"yAxis": {
"type": "value"
},
"series": [
{
"id": "s0",
"type": "bar"
},
{
"id": "s1",
"type": "bar"
},
{
"id": "s2",
"type": "bar"
}
]
}
},
{
"id": "dataset-objects",
"title": "同数据对象数组",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
{
"课程": "HTML",
"第1期": 12,
"第2期": 24,
"第3期": 18
},
{
"课程": "CSS",
"第1期": 16,
"第2期": 22,
"第3期": 29
},
{
"课程": "JavaScript",
"第1期": 21,
"第2期": 17,
"第3期": 34
},
{
"课程": "Web项目",
"第1期": 15,
"第2期": 26,
"第3期": 32
}
],
"dimensions": [
"课程",
"第1期",
"第2期",
"第3期"
]
},
"grid": {
"top": 65,
"bottom": 70,
"containLabel": true
},
"xAxis": {
"type": "category"
},
"yAxis": {
"type": "value"
},
"series": [
{
"id": "s0",
"type": "bar"
},
{
"id": "s1",
"type": "bar"
},
{
"id": "s2",
"type": "bar"
}
]
}
},
{
"id": "dataset-row-column",
"title": "双网格行列对照",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期",
"第4期"
],
[
"HTML",
12,
24,
18,
31
],
[
"CSS",
16,
22,
29,
27
],
[
"JavaScript",
21,
17,
34,
30
]
]
},
"grid": [
{
"top": 60,
"bottom": "55%",
"containLabel": true
},
{
"top": "60%",
"bottom": 40,
"containLabel": true
}
],
"xAxis": [
{
"type": "category",
"gridIndex": 0
},
{
"type": "category",
"gridIndex": 1
}
],
"yAxis": [
{
"gridIndex": 0
},
{
"gridIndex": 1
}
],
"series": [
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
}
]
}
},
{
"id": "dataset-encode",
"title": "显式水平编码",
"option": {
"animation": false,
"dataset": {
"source": [
[
"score",
"amount",
"product"
],
[
20,
120,
"阅读"
],
[
50,
240,
"实作"
],
[
80,
180,
"复习"
],
[
95,
310,
"调试"
],
[
10,
220,
"整理"
],
[
65,
270,
"回顾"
],
[
35,
160,
"表达"
],
[
72,
200,
"设计"
],
[
88,
260,
"验证"
]
]
},
"grid": {
"left": 90,
"right": 40,
"top": 55,
"bottom": 85
},
"xAxis": {
"type": "value",
"name": "amount"
},
"yAxis": {
"type": "category"
},
"series": [
{
"type": "bar",
"encode": {
"x": "amount",
"y": "product",
"tooltip": [
"product",
"score",
"amount"
]
}
}
]
}
},
{
"id": "dataset-four",
"title": "同一五维数据的四视图",
"option": {
"animation": false,
"dataset": {
"dimensions": [
"Income",
"Life Expectancy",
"Population",
"Country",
{
"name": "Year",
"type": "ordinal"
}
],
"source": [
[
"Income",
"Life Expectancy",
"Population",
"Country",
"Year"
],
[
10,
60,
20,
"地区甲",
2018
],
[
20,
65,
35,
"地区乙",
2019
],
[
30,
70,
15,
"地区丙",
2020
],
[
40,
75,
40,
"地区丁",
2021
]
]
},
"tooltip": {},
"grid": [
{
"left": 55,
"right": "55%",
"top": 45,
"bottom": "55%"
},
{
"left": "60%",
"right": 35,
"top": 45,
"bottom": "55%"
},
{
"left": 55,
"right": "55%",
"top": "60%",
"bottom": 45
},
{
"left": "60%",
"right": 35,
"top": "60%",
"bottom": 45
}
],
"xAxis": [
{
"type": "value",
"gridIndex": 0
},
{
"type": "category",
"gridIndex": 1
},
{
"type": "value",
"gridIndex": 2
},
{
"type": "value",
"gridIndex": 3
}
],
"yAxis": [
{
"type": "value",
"gridIndex": 0
},
{
"type": "value",
"gridIndex": 1
},
{
"type": "value",
"gridIndex": 2
},
{
"type": "value",
"gridIndex": 3
}
],
"series": [
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 0,
"yAxisIndex": 0,
"encode": {
"x": "Income",
"y": "Life Expectancy",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 1,
"yAxisIndex": 1,
"encode": {
"x": "Country",
"y": "Income",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 2,
"yAxisIndex": 2,
"encode": {
"x": "Income",
"y": "Population",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 3,
"yAxisIndex": 3,
"encode": {
"x": "Life Expectancy",
"y": "Population",
"tooltip": [
0,
1,
2,
3,
4
]
}
}
]
}
},
{
"id": "dataset-color",
"title": "score颜色与amount坐标分开",
"option": {
"animation": false,
"dataset": {
"source": [
[
"score",
"amount",
"product"
],
[
20,
120,
"阅读"
],
[
50,
240,
"实作"
],
[
80,
180,
"复习"
],
[
95,
310,
"调试"
],
[
10,
220,
"整理"
],
[
65,
270,
"回顾"
],
[
35,
160,
"表达"
],
[
72,
200,
"设计"
],
[
88,
260,
"验证"
]
]
},
"grid": {
"left": 90,
"right": 40,
"top": 55,
"bottom": 85
},
"xAxis": {
"type": "value",
"name": "amount"
},
"yAxis": {
"type": "category"
},
"series": [
{
"type": "bar",
"encode": {
"x": "amount",
"y": "product",
"tooltip": [
"product",
"score",
"amount"
]
}
}
],
"visualMap": {
"type": "continuous",
"min": 0,
"max": 100,
"dimension": 0,
"orient": "horizontal",
"bottom": 5,
"inRange": {
"color": [
"#d7da8b",
"#e15457"
]
}
}
}
},
{
"id": "dataset-linked",
"title": "折线和饼图共享并联动",
"option": {
"animation": false,
"legend": {
"bottom": 0
},
"tooltip": {
"trigger": "axis",
"showContent": false
},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期",
"第4期",
"第5期",
"第6期"
],
[
"HTML",
12,
24,
18,
31,
33,
35
],
[
"CSS",
16,
22,
29,
27,
29,
31
],
[
"JavaScript",
21,
17,
34,
30,
32,
34
],
[
"Web项目",
15,
26,
32,
38,
40,
42
]
]
},
"xAxis": {
"type": "category"
},
"yAxis": {},
"grid": {
"top": "55%",
"bottom": 70
},
"series": [
{
"id": "course-0",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-1",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-2",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-3",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "linked-pie",
"type": "pie",
"radius": "25%",
"center": [
"50%",
"25%"
],
"label": {
"formatter": "{b}: {@第1期} ({d}%)"
},
"encode": {
"itemName": "课程",
"value": "第1期",
"tooltip": "第1期"
}
}
]
},
"behavior": "linked"
}
]
};
export default async function run(){await mount(echarts,specification);}
查看独立实例 ↗ 在独立页面查看源码、运行环境与工程包
- 本章所有变体真实渲染,实际图元和状态与本章教学条件对应
- 不同初始化、轴/数据编码、状态分支或媒体布局分别核对
- 定时器、请求及容器观察器在销毁后释放,不以模拟文字代替实际运行
同数据对象数组:独立实例
展开查看收起
import * as echarts from 'echarts';
import {mount} from './lab.js';
// 本章独立配置和实际运行共用;数值均为自有虚构数据。
const specification = {
"key": "echarts-dataset",
"title": "ECharts dataset:行列、encode及图表联动",
"cases": [
{
"id": "dataset-matrix",
"title": "二维数组三系列",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期"
],
[
"HTML",
12,
24,
18
],
[
"CSS",
16,
22,
29
],
[
"JavaScript",
21,
17,
34
],
[
"Web项目",
15,
26,
32
]
]
},
"grid": {
"top": 65,
"bottom": 70,
"containLabel": true
},
"xAxis": {
"type": "category"
},
"yAxis": {
"type": "value"
},
"series": [
{
"id": "s0",
"type": "bar"
},
{
"id": "s1",
"type": "bar"
},
{
"id": "s2",
"type": "bar"
}
]
}
},
{
"id": "dataset-objects",
"title": "同数据对象数组",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
{
"课程": "HTML",
"第1期": 12,
"第2期": 24,
"第3期": 18
},
{
"课程": "CSS",
"第1期": 16,
"第2期": 22,
"第3期": 29
},
{
"课程": "JavaScript",
"第1期": 21,
"第2期": 17,
"第3期": 34
},
{
"课程": "Web项目",
"第1期": 15,
"第2期": 26,
"第3期": 32
}
],
"dimensions": [
"课程",
"第1期",
"第2期",
"第3期"
]
},
"grid": {
"top": 65,
"bottom": 70,
"containLabel": true
},
"xAxis": {
"type": "category"
},
"yAxis": {
"type": "value"
},
"series": [
{
"id": "s0",
"type": "bar"
},
{
"id": "s1",
"type": "bar"
},
{
"id": "s2",
"type": "bar"
}
]
}
},
{
"id": "dataset-row-column",
"title": "双网格行列对照",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期",
"第4期"
],
[
"HTML",
12,
24,
18,
31
],
[
"CSS",
16,
22,
29,
27
],
[
"JavaScript",
21,
17,
34,
30
]
]
},
"grid": [
{
"top": 60,
"bottom": "55%",
"containLabel": true
},
{
"top": "60%",
"bottom": 40,
"containLabel": true
}
],
"xAxis": [
{
"type": "category",
"gridIndex": 0
},
{
"type": "category",
"gridIndex": 1
}
],
"yAxis": [
{
"gridIndex": 0
},
{
"gridIndex": 1
}
],
"series": [
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
}
]
}
},
{
"id": "dataset-encode",
"title": "显式水平编码",
"option": {
"animation": false,
"dataset": {
"source": [
[
"score",
"amount",
"product"
],
[
20,
120,
"阅读"
],
[
50,
240,
"实作"
],
[
80,
180,
"复习"
],
[
95,
310,
"调试"
],
[
10,
220,
"整理"
],
[
65,
270,
"回顾"
],
[
35,
160,
"表达"
],
[
72,
200,
"设计"
],
[
88,
260,
"验证"
]
]
},
"grid": {
"left": 90,
"right": 40,
"top": 55,
"bottom": 85
},
"xAxis": {
"type": "value",
"name": "amount"
},
"yAxis": {
"type": "category"
},
"series": [
{
"type": "bar",
"encode": {
"x": "amount",
"y": "product",
"tooltip": [
"product",
"score",
"amount"
]
}
}
]
}
},
{
"id": "dataset-four",
"title": "同一五维数据的四视图",
"option": {
"animation": false,
"dataset": {
"dimensions": [
"Income",
"Life Expectancy",
"Population",
"Country",
{
"name": "Year",
"type": "ordinal"
}
],
"source": [
[
"Income",
"Life Expectancy",
"Population",
"Country",
"Year"
],
[
10,
60,
20,
"地区甲",
2018
],
[
20,
65,
35,
"地区乙",
2019
],
[
30,
70,
15,
"地区丙",
2020
],
[
40,
75,
40,
"地区丁",
2021
]
]
},
"tooltip": {},
"grid": [
{
"left": 55,
"right": "55%",
"top": 45,
"bottom": "55%"
},
{
"left": "60%",
"right": 35,
"top": 45,
"bottom": "55%"
},
{
"left": 55,
"right": "55%",
"top": "60%",
"bottom": 45
},
{
"left": "60%",
"right": 35,
"top": "60%",
"bottom": 45
}
],
"xAxis": [
{
"type": "value",
"gridIndex": 0
},
{
"type": "category",
"gridIndex": 1
},
{
"type": "value",
"gridIndex": 2
},
{
"type": "value",
"gridIndex": 3
}
],
"yAxis": [
{
"type": "value",
"gridIndex": 0
},
{
"type": "value",
"gridIndex": 1
},
{
"type": "value",
"gridIndex": 2
},
{
"type": "value",
"gridIndex": 3
}
],
"series": [
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 0,
"yAxisIndex": 0,
"encode": {
"x": "Income",
"y": "Life Expectancy",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 1,
"yAxisIndex": 1,
"encode": {
"x": "Country",
"y": "Income",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 2,
"yAxisIndex": 2,
"encode": {
"x": "Income",
"y": "Population",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 3,
"yAxisIndex": 3,
"encode": {
"x": "Life Expectancy",
"y": "Population",
"tooltip": [
0,
1,
2,
3,
4
]
}
}
]
}
},
{
"id": "dataset-color",
"title": "score颜色与amount坐标分开",
"option": {
"animation": false,
"dataset": {
"source": [
[
"score",
"amount",
"product"
],
[
20,
120,
"阅读"
],
[
50,
240,
"实作"
],
[
80,
180,
"复习"
],
[
95,
310,
"调试"
],
[
10,
220,
"整理"
],
[
65,
270,
"回顾"
],
[
35,
160,
"表达"
],
[
72,
200,
"设计"
],
[
88,
260,
"验证"
]
]
},
"grid": {
"left": 90,
"right": 40,
"top": 55,
"bottom": 85
},
"xAxis": {
"type": "value",
"name": "amount"
},
"yAxis": {
"type": "category"
},
"series": [
{
"type": "bar",
"encode": {
"x": "amount",
"y": "product",
"tooltip": [
"product",
"score",
"amount"
]
}
}
],
"visualMap": {
"type": "continuous",
"min": 0,
"max": 100,
"dimension": 0,
"orient": "horizontal",
"bottom": 5,
"inRange": {
"color": [
"#d7da8b",
"#e15457"
]
}
}
}
},
{
"id": "dataset-linked",
"title": "折线和饼图共享并联动",
"option": {
"animation": false,
"legend": {
"bottom": 0
},
"tooltip": {
"trigger": "axis",
"showContent": false
},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期",
"第4期",
"第5期",
"第6期"
],
[
"HTML",
12,
24,
18,
31,
33,
35
],
[
"CSS",
16,
22,
29,
27,
29,
31
],
[
"JavaScript",
21,
17,
34,
30,
32,
34
],
[
"Web项目",
15,
26,
32,
38,
40,
42
]
]
},
"xAxis": {
"type": "category"
},
"yAxis": {},
"grid": {
"top": "55%",
"bottom": 70
},
"series": [
{
"id": "course-0",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-1",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-2",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-3",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "linked-pie",
"type": "pie",
"radius": "25%",
"center": [
"50%",
"25%"
],
"label": {
"formatter": "{b}: {@第1期} ({d}%)"
},
"encode": {
"itemName": "课程",
"value": "第1期",
"tooltip": "第1期"
}
}
]
},
"behavior": "linked"
}
]
};
export default async function run(){await mount(echarts,specification);}
查看独立实例 ↗ 在独立页面查看源码、运行环境与工程包
- 对应变体真实运行;其数据、图元、事件或状态独立记录
双网格行列对照:独立实例
展开查看收起
import * as echarts from 'echarts';
import {mount} from './lab.js';
// 本章独立配置和实际运行共用;数值均为自有虚构数据。
const specification = {
"key": "echarts-dataset",
"title": "ECharts dataset:行列、encode及图表联动",
"cases": [
{
"id": "dataset-matrix",
"title": "二维数组三系列",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期"
],
[
"HTML",
12,
24,
18
],
[
"CSS",
16,
22,
29
],
[
"JavaScript",
21,
17,
34
],
[
"Web项目",
15,
26,
32
]
]
},
"grid": {
"top": 65,
"bottom": 70,
"containLabel": true
},
"xAxis": {
"type": "category"
},
"yAxis": {
"type": "value"
},
"series": [
{
"id": "s0",
"type": "bar"
},
{
"id": "s1",
"type": "bar"
},
{
"id": "s2",
"type": "bar"
}
]
}
},
{
"id": "dataset-objects",
"title": "同数据对象数组",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
{
"课程": "HTML",
"第1期": 12,
"第2期": 24,
"第3期": 18
},
{
"课程": "CSS",
"第1期": 16,
"第2期": 22,
"第3期": 29
},
{
"课程": "JavaScript",
"第1期": 21,
"第2期": 17,
"第3期": 34
},
{
"课程": "Web项目",
"第1期": 15,
"第2期": 26,
"第3期": 32
}
],
"dimensions": [
"课程",
"第1期",
"第2期",
"第3期"
]
},
"grid": {
"top": 65,
"bottom": 70,
"containLabel": true
},
"xAxis": {
"type": "category"
},
"yAxis": {
"type": "value"
},
"series": [
{
"id": "s0",
"type": "bar"
},
{
"id": "s1",
"type": "bar"
},
{
"id": "s2",
"type": "bar"
}
]
}
},
{
"id": "dataset-row-column",
"title": "双网格行列对照",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期",
"第4期"
],
[
"HTML",
12,
24,
18,
31
],
[
"CSS",
16,
22,
29,
27
],
[
"JavaScript",
21,
17,
34,
30
]
]
},
"grid": [
{
"top": 60,
"bottom": "55%",
"containLabel": true
},
{
"top": "60%",
"bottom": 40,
"containLabel": true
}
],
"xAxis": [
{
"type": "category",
"gridIndex": 0
},
{
"type": "category",
"gridIndex": 1
}
],
"yAxis": [
{
"gridIndex": 0
},
{
"gridIndex": 1
}
],
"series": [
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
}
]
}
},
{
"id": "dataset-encode",
"title": "显式水平编码",
"option": {
"animation": false,
"dataset": {
"source": [
[
"score",
"amount",
"product"
],
[
20,
120,
"阅读"
],
[
50,
240,
"实作"
],
[
80,
180,
"复习"
],
[
95,
310,
"调试"
],
[
10,
220,
"整理"
],
[
65,
270,
"回顾"
],
[
35,
160,
"表达"
],
[
72,
200,
"设计"
],
[
88,
260,
"验证"
]
]
},
"grid": {
"left": 90,
"right": 40,
"top": 55,
"bottom": 85
},
"xAxis": {
"type": "value",
"name": "amount"
},
"yAxis": {
"type": "category"
},
"series": [
{
"type": "bar",
"encode": {
"x": "amount",
"y": "product",
"tooltip": [
"product",
"score",
"amount"
]
}
}
]
}
},
{
"id": "dataset-four",
"title": "同一五维数据的四视图",
"option": {
"animation": false,
"dataset": {
"dimensions": [
"Income",
"Life Expectancy",
"Population",
"Country",
{
"name": "Year",
"type": "ordinal"
}
],
"source": [
[
"Income",
"Life Expectancy",
"Population",
"Country",
"Year"
],
[
10,
60,
20,
"地区甲",
2018
],
[
20,
65,
35,
"地区乙",
2019
],
[
30,
70,
15,
"地区丙",
2020
],
[
40,
75,
40,
"地区丁",
2021
]
]
},
"tooltip": {},
"grid": [
{
"left": 55,
"right": "55%",
"top": 45,
"bottom": "55%"
},
{
"left": "60%",
"right": 35,
"top": 45,
"bottom": "55%"
},
{
"left": 55,
"right": "55%",
"top": "60%",
"bottom": 45
},
{
"left": "60%",
"right": 35,
"top": "60%",
"bottom": 45
}
],
"xAxis": [
{
"type": "value",
"gridIndex": 0
},
{
"type": "category",
"gridIndex": 1
},
{
"type": "value",
"gridIndex": 2
},
{
"type": "value",
"gridIndex": 3
}
],
"yAxis": [
{
"type": "value",
"gridIndex": 0
},
{
"type": "value",
"gridIndex": 1
},
{
"type": "value",
"gridIndex": 2
},
{
"type": "value",
"gridIndex": 3
}
],
"series": [
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 0,
"yAxisIndex": 0,
"encode": {
"x": "Income",
"y": "Life Expectancy",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 1,
"yAxisIndex": 1,
"encode": {
"x": "Country",
"y": "Income",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 2,
"yAxisIndex": 2,
"encode": {
"x": "Income",
"y": "Population",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 3,
"yAxisIndex": 3,
"encode": {
"x": "Life Expectancy",
"y": "Population",
"tooltip": [
0,
1,
2,
3,
4
]
}
}
]
}
},
{
"id": "dataset-color",
"title": "score颜色与amount坐标分开",
"option": {
"animation": false,
"dataset": {
"source": [
[
"score",
"amount",
"product"
],
[
20,
120,
"阅读"
],
[
50,
240,
"实作"
],
[
80,
180,
"复习"
],
[
95,
310,
"调试"
],
[
10,
220,
"整理"
],
[
65,
270,
"回顾"
],
[
35,
160,
"表达"
],
[
72,
200,
"设计"
],
[
88,
260,
"验证"
]
]
},
"grid": {
"left": 90,
"right": 40,
"top": 55,
"bottom": 85
},
"xAxis": {
"type": "value",
"name": "amount"
},
"yAxis": {
"type": "category"
},
"series": [
{
"type": "bar",
"encode": {
"x": "amount",
"y": "product",
"tooltip": [
"product",
"score",
"amount"
]
}
}
],
"visualMap": {
"type": "continuous",
"min": 0,
"max": 100,
"dimension": 0,
"orient": "horizontal",
"bottom": 5,
"inRange": {
"color": [
"#d7da8b",
"#e15457"
]
}
}
}
},
{
"id": "dataset-linked",
"title": "折线和饼图共享并联动",
"option": {
"animation": false,
"legend": {
"bottom": 0
},
"tooltip": {
"trigger": "axis",
"showContent": false
},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期",
"第4期",
"第5期",
"第6期"
],
[
"HTML",
12,
24,
18,
31,
33,
35
],
[
"CSS",
16,
22,
29,
27,
29,
31
],
[
"JavaScript",
21,
17,
34,
30,
32,
34
],
[
"Web项目",
15,
26,
32,
38,
40,
42
]
]
},
"xAxis": {
"type": "category"
},
"yAxis": {},
"grid": {
"top": "55%",
"bottom": 70
},
"series": [
{
"id": "course-0",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-1",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-2",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-3",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "linked-pie",
"type": "pie",
"radius": "25%",
"center": [
"50%",
"25%"
],
"label": {
"formatter": "{b}: {@第1期} ({d}%)"
},
"encode": {
"itemName": "课程",
"value": "第1期",
"tooltip": "第1期"
}
}
]
},
"behavior": "linked"
}
]
};
export default async function run(){await mount(echarts,specification);}
查看独立实例 ↗ 在独立页面查看源码、运行环境与工程包
- 对应变体真实运行;其数据、图元、事件或状态独立记录
显式水平编码:独立实例
展开查看收起
import * as echarts from 'echarts';
import {mount} from './lab.js';
// 本章独立配置和实际运行共用;数值均为自有虚构数据。
const specification = {
"key": "echarts-dataset",
"title": "ECharts dataset:行列、encode及图表联动",
"cases": [
{
"id": "dataset-matrix",
"title": "二维数组三系列",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期"
],
[
"HTML",
12,
24,
18
],
[
"CSS",
16,
22,
29
],
[
"JavaScript",
21,
17,
34
],
[
"Web项目",
15,
26,
32
]
]
},
"grid": {
"top": 65,
"bottom": 70,
"containLabel": true
},
"xAxis": {
"type": "category"
},
"yAxis": {
"type": "value"
},
"series": [
{
"id": "s0",
"type": "bar"
},
{
"id": "s1",
"type": "bar"
},
{
"id": "s2",
"type": "bar"
}
]
}
},
{
"id": "dataset-objects",
"title": "同数据对象数组",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
{
"课程": "HTML",
"第1期": 12,
"第2期": 24,
"第3期": 18
},
{
"课程": "CSS",
"第1期": 16,
"第2期": 22,
"第3期": 29
},
{
"课程": "JavaScript",
"第1期": 21,
"第2期": 17,
"第3期": 34
},
{
"课程": "Web项目",
"第1期": 15,
"第2期": 26,
"第3期": 32
}
],
"dimensions": [
"课程",
"第1期",
"第2期",
"第3期"
]
},
"grid": {
"top": 65,
"bottom": 70,
"containLabel": true
},
"xAxis": {
"type": "category"
},
"yAxis": {
"type": "value"
},
"series": [
{
"id": "s0",
"type": "bar"
},
{
"id": "s1",
"type": "bar"
},
{
"id": "s2",
"type": "bar"
}
]
}
},
{
"id": "dataset-row-column",
"title": "双网格行列对照",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期",
"第4期"
],
[
"HTML",
12,
24,
18,
31
],
[
"CSS",
16,
22,
29,
27
],
[
"JavaScript",
21,
17,
34,
30
]
]
},
"grid": [
{
"top": 60,
"bottom": "55%",
"containLabel": true
},
{
"top": "60%",
"bottom": 40,
"containLabel": true
}
],
"xAxis": [
{
"type": "category",
"gridIndex": 0
},
{
"type": "category",
"gridIndex": 1
}
],
"yAxis": [
{
"gridIndex": 0
},
{
"gridIndex": 1
}
],
"series": [
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
}
]
}
},
{
"id": "dataset-encode",
"title": "显式水平编码",
"option": {
"animation": false,
"dataset": {
"source": [
[
"score",
"amount",
"product"
],
[
20,
120,
"阅读"
],
[
50,
240,
"实作"
],
[
80,
180,
"复习"
],
[
95,
310,
"调试"
],
[
10,
220,
"整理"
],
[
65,
270,
"回顾"
],
[
35,
160,
"表达"
],
[
72,
200,
"设计"
],
[
88,
260,
"验证"
]
]
},
"grid": {
"left": 90,
"right": 40,
"top": 55,
"bottom": 85
},
"xAxis": {
"type": "value",
"name": "amount"
},
"yAxis": {
"type": "category"
},
"series": [
{
"type": "bar",
"encode": {
"x": "amount",
"y": "product",
"tooltip": [
"product",
"score",
"amount"
]
}
}
]
}
},
{
"id": "dataset-four",
"title": "同一五维数据的四视图",
"option": {
"animation": false,
"dataset": {
"dimensions": [
"Income",
"Life Expectancy",
"Population",
"Country",
{
"name": "Year",
"type": "ordinal"
}
],
"source": [
[
"Income",
"Life Expectancy",
"Population",
"Country",
"Year"
],
[
10,
60,
20,
"地区甲",
2018
],
[
20,
65,
35,
"地区乙",
2019
],
[
30,
70,
15,
"地区丙",
2020
],
[
40,
75,
40,
"地区丁",
2021
]
]
},
"tooltip": {},
"grid": [
{
"left": 55,
"right": "55%",
"top": 45,
"bottom": "55%"
},
{
"left": "60%",
"right": 35,
"top": 45,
"bottom": "55%"
},
{
"left": 55,
"right": "55%",
"top": "60%",
"bottom": 45
},
{
"left": "60%",
"right": 35,
"top": "60%",
"bottom": 45
}
],
"xAxis": [
{
"type": "value",
"gridIndex": 0
},
{
"type": "category",
"gridIndex": 1
},
{
"type": "value",
"gridIndex": 2
},
{
"type": "value",
"gridIndex": 3
}
],
"yAxis": [
{
"type": "value",
"gridIndex": 0
},
{
"type": "value",
"gridIndex": 1
},
{
"type": "value",
"gridIndex": 2
},
{
"type": "value",
"gridIndex": 3
}
],
"series": [
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 0,
"yAxisIndex": 0,
"encode": {
"x": "Income",
"y": "Life Expectancy",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 1,
"yAxisIndex": 1,
"encode": {
"x": "Country",
"y": "Income",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 2,
"yAxisIndex": 2,
"encode": {
"x": "Income",
"y": "Population",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 3,
"yAxisIndex": 3,
"encode": {
"x": "Life Expectancy",
"y": "Population",
"tooltip": [
0,
1,
2,
3,
4
]
}
}
]
}
},
{
"id": "dataset-color",
"title": "score颜色与amount坐标分开",
"option": {
"animation": false,
"dataset": {
"source": [
[
"score",
"amount",
"product"
],
[
20,
120,
"阅读"
],
[
50,
240,
"实作"
],
[
80,
180,
"复习"
],
[
95,
310,
"调试"
],
[
10,
220,
"整理"
],
[
65,
270,
"回顾"
],
[
35,
160,
"表达"
],
[
72,
200,
"设计"
],
[
88,
260,
"验证"
]
]
},
"grid": {
"left": 90,
"right": 40,
"top": 55,
"bottom": 85
},
"xAxis": {
"type": "value",
"name": "amount"
},
"yAxis": {
"type": "category"
},
"series": [
{
"type": "bar",
"encode": {
"x": "amount",
"y": "product",
"tooltip": [
"product",
"score",
"amount"
]
}
}
],
"visualMap": {
"type": "continuous",
"min": 0,
"max": 100,
"dimension": 0,
"orient": "horizontal",
"bottom": 5,
"inRange": {
"color": [
"#d7da8b",
"#e15457"
]
}
}
}
},
{
"id": "dataset-linked",
"title": "折线和饼图共享并联动",
"option": {
"animation": false,
"legend": {
"bottom": 0
},
"tooltip": {
"trigger": "axis",
"showContent": false
},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期",
"第4期",
"第5期",
"第6期"
],
[
"HTML",
12,
24,
18,
31,
33,
35
],
[
"CSS",
16,
22,
29,
27,
29,
31
],
[
"JavaScript",
21,
17,
34,
30,
32,
34
],
[
"Web项目",
15,
26,
32,
38,
40,
42
]
]
},
"xAxis": {
"type": "category"
},
"yAxis": {},
"grid": {
"top": "55%",
"bottom": 70
},
"series": [
{
"id": "course-0",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-1",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-2",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-3",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "linked-pie",
"type": "pie",
"radius": "25%",
"center": [
"50%",
"25%"
],
"label": {
"formatter": "{b}: {@第1期} ({d}%)"
},
"encode": {
"itemName": "课程",
"value": "第1期",
"tooltip": "第1期"
}
}
]
},
"behavior": "linked"
}
]
};
export default async function run(){await mount(echarts,specification);}
查看独立实例 ↗ 在独立页面查看源码、运行环境与工程包
- 对应变体真实运行;其数据、图元、事件或状态独立记录
同一五维数据的四视图:独立实例
展开查看收起
import * as echarts from 'echarts';
import {mount} from './lab.js';
// 本章独立配置和实际运行共用;数值均为自有虚构数据。
const specification = {
"key": "echarts-dataset",
"title": "ECharts dataset:行列、encode及图表联动",
"cases": [
{
"id": "dataset-matrix",
"title": "二维数组三系列",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期"
],
[
"HTML",
12,
24,
18
],
[
"CSS",
16,
22,
29
],
[
"JavaScript",
21,
17,
34
],
[
"Web项目",
15,
26,
32
]
]
},
"grid": {
"top": 65,
"bottom": 70,
"containLabel": true
},
"xAxis": {
"type": "category"
},
"yAxis": {
"type": "value"
},
"series": [
{
"id": "s0",
"type": "bar"
},
{
"id": "s1",
"type": "bar"
},
{
"id": "s2",
"type": "bar"
}
]
}
},
{
"id": "dataset-objects",
"title": "同数据对象数组",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
{
"课程": "HTML",
"第1期": 12,
"第2期": 24,
"第3期": 18
},
{
"课程": "CSS",
"第1期": 16,
"第2期": 22,
"第3期": 29
},
{
"课程": "JavaScript",
"第1期": 21,
"第2期": 17,
"第3期": 34
},
{
"课程": "Web项目",
"第1期": 15,
"第2期": 26,
"第3期": 32
}
],
"dimensions": [
"课程",
"第1期",
"第2期",
"第3期"
]
},
"grid": {
"top": 65,
"bottom": 70,
"containLabel": true
},
"xAxis": {
"type": "category"
},
"yAxis": {
"type": "value"
},
"series": [
{
"id": "s0",
"type": "bar"
},
{
"id": "s1",
"type": "bar"
},
{
"id": "s2",
"type": "bar"
}
]
}
},
{
"id": "dataset-row-column",
"title": "双网格行列对照",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期",
"第4期"
],
[
"HTML",
12,
24,
18,
31
],
[
"CSS",
16,
22,
29,
27
],
[
"JavaScript",
21,
17,
34,
30
]
]
},
"grid": [
{
"top": 60,
"bottom": "55%",
"containLabel": true
},
{
"top": "60%",
"bottom": 40,
"containLabel": true
}
],
"xAxis": [
{
"type": "category",
"gridIndex": 0
},
{
"type": "category",
"gridIndex": 1
}
],
"yAxis": [
{
"gridIndex": 0
},
{
"gridIndex": 1
}
],
"series": [
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
}
]
}
},
{
"id": "dataset-encode",
"title": "显式水平编码",
"option": {
"animation": false,
"dataset": {
"source": [
[
"score",
"amount",
"product"
],
[
20,
120,
"阅读"
],
[
50,
240,
"实作"
],
[
80,
180,
"复习"
],
[
95,
310,
"调试"
],
[
10,
220,
"整理"
],
[
65,
270,
"回顾"
],
[
35,
160,
"表达"
],
[
72,
200,
"设计"
],
[
88,
260,
"验证"
]
]
},
"grid": {
"left": 90,
"right": 40,
"top": 55,
"bottom": 85
},
"xAxis": {
"type": "value",
"name": "amount"
},
"yAxis": {
"type": "category"
},
"series": [
{
"type": "bar",
"encode": {
"x": "amount",
"y": "product",
"tooltip": [
"product",
"score",
"amount"
]
}
}
]
}
},
{
"id": "dataset-four",
"title": "同一五维数据的四视图",
"option": {
"animation": false,
"dataset": {
"dimensions": [
"Income",
"Life Expectancy",
"Population",
"Country",
{
"name": "Year",
"type": "ordinal"
}
],
"source": [
[
"Income",
"Life Expectancy",
"Population",
"Country",
"Year"
],
[
10,
60,
20,
"地区甲",
2018
],
[
20,
65,
35,
"地区乙",
2019
],
[
30,
70,
15,
"地区丙",
2020
],
[
40,
75,
40,
"地区丁",
2021
]
]
},
"tooltip": {},
"grid": [
{
"left": 55,
"right": "55%",
"top": 45,
"bottom": "55%"
},
{
"left": "60%",
"right": 35,
"top": 45,
"bottom": "55%"
},
{
"left": 55,
"right": "55%",
"top": "60%",
"bottom": 45
},
{
"left": "60%",
"right": 35,
"top": "60%",
"bottom": 45
}
],
"xAxis": [
{
"type": "value",
"gridIndex": 0
},
{
"type": "category",
"gridIndex": 1
},
{
"type": "value",
"gridIndex": 2
},
{
"type": "value",
"gridIndex": 3
}
],
"yAxis": [
{
"type": "value",
"gridIndex": 0
},
{
"type": "value",
"gridIndex": 1
},
{
"type": "value",
"gridIndex": 2
},
{
"type": "value",
"gridIndex": 3
}
],
"series": [
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 0,
"yAxisIndex": 0,
"encode": {
"x": "Income",
"y": "Life Expectancy",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 1,
"yAxisIndex": 1,
"encode": {
"x": "Country",
"y": "Income",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 2,
"yAxisIndex": 2,
"encode": {
"x": "Income",
"y": "Population",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 3,
"yAxisIndex": 3,
"encode": {
"x": "Life Expectancy",
"y": "Population",
"tooltip": [
0,
1,
2,
3,
4
]
}
}
]
}
},
{
"id": "dataset-color",
"title": "score颜色与amount坐标分开",
"option": {
"animation": false,
"dataset": {
"source": [
[
"score",
"amount",
"product"
],
[
20,
120,
"阅读"
],
[
50,
240,
"实作"
],
[
80,
180,
"复习"
],
[
95,
310,
"调试"
],
[
10,
220,
"整理"
],
[
65,
270,
"回顾"
],
[
35,
160,
"表达"
],
[
72,
200,
"设计"
],
[
88,
260,
"验证"
]
]
},
"grid": {
"left": 90,
"right": 40,
"top": 55,
"bottom": 85
},
"xAxis": {
"type": "value",
"name": "amount"
},
"yAxis": {
"type": "category"
},
"series": [
{
"type": "bar",
"encode": {
"x": "amount",
"y": "product",
"tooltip": [
"product",
"score",
"amount"
]
}
}
],
"visualMap": {
"type": "continuous",
"min": 0,
"max": 100,
"dimension": 0,
"orient": "horizontal",
"bottom": 5,
"inRange": {
"color": [
"#d7da8b",
"#e15457"
]
}
}
}
},
{
"id": "dataset-linked",
"title": "折线和饼图共享并联动",
"option": {
"animation": false,
"legend": {
"bottom": 0
},
"tooltip": {
"trigger": "axis",
"showContent": false
},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期",
"第4期",
"第5期",
"第6期"
],
[
"HTML",
12,
24,
18,
31,
33,
35
],
[
"CSS",
16,
22,
29,
27,
29,
31
],
[
"JavaScript",
21,
17,
34,
30,
32,
34
],
[
"Web项目",
15,
26,
32,
38,
40,
42
]
]
},
"xAxis": {
"type": "category"
},
"yAxis": {},
"grid": {
"top": "55%",
"bottom": 70
},
"series": [
{
"id": "course-0",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-1",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-2",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-3",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "linked-pie",
"type": "pie",
"radius": "25%",
"center": [
"50%",
"25%"
],
"label": {
"formatter": "{b}: {@第1期} ({d}%)"
},
"encode": {
"itemName": "课程",
"value": "第1期",
"tooltip": "第1期"
}
}
]
},
"behavior": "linked"
}
]
};
export default async function run(){await mount(echarts,specification);}
查看独立实例 ↗ 在独立页面查看源码、运行环境与工程包
- 对应变体真实运行;其数据、图元、事件或状态独立记录
score颜色与amount坐标分开:独立实例
展开查看收起
import * as echarts from 'echarts';
import {mount} from './lab.js';
// 本章独立配置和实际运行共用;数值均为自有虚构数据。
const specification = {
"key": "echarts-dataset",
"title": "ECharts dataset:行列、encode及图表联动",
"cases": [
{
"id": "dataset-matrix",
"title": "二维数组三系列",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期"
],
[
"HTML",
12,
24,
18
],
[
"CSS",
16,
22,
29
],
[
"JavaScript",
21,
17,
34
],
[
"Web项目",
15,
26,
32
]
]
},
"grid": {
"top": 65,
"bottom": 70,
"containLabel": true
},
"xAxis": {
"type": "category"
},
"yAxis": {
"type": "value"
},
"series": [
{
"id": "s0",
"type": "bar"
},
{
"id": "s1",
"type": "bar"
},
{
"id": "s2",
"type": "bar"
}
]
}
},
{
"id": "dataset-objects",
"title": "同数据对象数组",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
{
"课程": "HTML",
"第1期": 12,
"第2期": 24,
"第3期": 18
},
{
"课程": "CSS",
"第1期": 16,
"第2期": 22,
"第3期": 29
},
{
"课程": "JavaScript",
"第1期": 21,
"第2期": 17,
"第3期": 34
},
{
"课程": "Web项目",
"第1期": 15,
"第2期": 26,
"第3期": 32
}
],
"dimensions": [
"课程",
"第1期",
"第2期",
"第3期"
]
},
"grid": {
"top": 65,
"bottom": 70,
"containLabel": true
},
"xAxis": {
"type": "category"
},
"yAxis": {
"type": "value"
},
"series": [
{
"id": "s0",
"type": "bar"
},
{
"id": "s1",
"type": "bar"
},
{
"id": "s2",
"type": "bar"
}
]
}
},
{
"id": "dataset-row-column",
"title": "双网格行列对照",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期",
"第4期"
],
[
"HTML",
12,
24,
18,
31
],
[
"CSS",
16,
22,
29,
27
],
[
"JavaScript",
21,
17,
34,
30
]
]
},
"grid": [
{
"top": 60,
"bottom": "55%",
"containLabel": true
},
{
"top": "60%",
"bottom": 40,
"containLabel": true
}
],
"xAxis": [
{
"type": "category",
"gridIndex": 0
},
{
"type": "category",
"gridIndex": 1
}
],
"yAxis": [
{
"gridIndex": 0
},
{
"gridIndex": 1
}
],
"series": [
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
}
]
}
},
{
"id": "dataset-encode",
"title": "显式水平编码",
"option": {
"animation": false,
"dataset": {
"source": [
[
"score",
"amount",
"product"
],
[
20,
120,
"阅读"
],
[
50,
240,
"实作"
],
[
80,
180,
"复习"
],
[
95,
310,
"调试"
],
[
10,
220,
"整理"
],
[
65,
270,
"回顾"
],
[
35,
160,
"表达"
],
[
72,
200,
"设计"
],
[
88,
260,
"验证"
]
]
},
"grid": {
"left": 90,
"right": 40,
"top": 55,
"bottom": 85
},
"xAxis": {
"type": "value",
"name": "amount"
},
"yAxis": {
"type": "category"
},
"series": [
{
"type": "bar",
"encode": {
"x": "amount",
"y": "product",
"tooltip": [
"product",
"score",
"amount"
]
}
}
]
}
},
{
"id": "dataset-four",
"title": "同一五维数据的四视图",
"option": {
"animation": false,
"dataset": {
"dimensions": [
"Income",
"Life Expectancy",
"Population",
"Country",
{
"name": "Year",
"type": "ordinal"
}
],
"source": [
[
"Income",
"Life Expectancy",
"Population",
"Country",
"Year"
],
[
10,
60,
20,
"地区甲",
2018
],
[
20,
65,
35,
"地区乙",
2019
],
[
30,
70,
15,
"地区丙",
2020
],
[
40,
75,
40,
"地区丁",
2021
]
]
},
"tooltip": {},
"grid": [
{
"left": 55,
"right": "55%",
"top": 45,
"bottom": "55%"
},
{
"left": "60%",
"right": 35,
"top": 45,
"bottom": "55%"
},
{
"left": 55,
"right": "55%",
"top": "60%",
"bottom": 45
},
{
"left": "60%",
"right": 35,
"top": "60%",
"bottom": 45
}
],
"xAxis": [
{
"type": "value",
"gridIndex": 0
},
{
"type": "category",
"gridIndex": 1
},
{
"type": "value",
"gridIndex": 2
},
{
"type": "value",
"gridIndex": 3
}
],
"yAxis": [
{
"type": "value",
"gridIndex": 0
},
{
"type": "value",
"gridIndex": 1
},
{
"type": "value",
"gridIndex": 2
},
{
"type": "value",
"gridIndex": 3
}
],
"series": [
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 0,
"yAxisIndex": 0,
"encode": {
"x": "Income",
"y": "Life Expectancy",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 1,
"yAxisIndex": 1,
"encode": {
"x": "Country",
"y": "Income",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 2,
"yAxisIndex": 2,
"encode": {
"x": "Income",
"y": "Population",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 3,
"yAxisIndex": 3,
"encode": {
"x": "Life Expectancy",
"y": "Population",
"tooltip": [
0,
1,
2,
3,
4
]
}
}
]
}
},
{
"id": "dataset-color",
"title": "score颜色与amount坐标分开",
"option": {
"animation": false,
"dataset": {
"source": [
[
"score",
"amount",
"product"
],
[
20,
120,
"阅读"
],
[
50,
240,
"实作"
],
[
80,
180,
"复习"
],
[
95,
310,
"调试"
],
[
10,
220,
"整理"
],
[
65,
270,
"回顾"
],
[
35,
160,
"表达"
],
[
72,
200,
"设计"
],
[
88,
260,
"验证"
]
]
},
"grid": {
"left": 90,
"right": 40,
"top": 55,
"bottom": 85
},
"xAxis": {
"type": "value",
"name": "amount"
},
"yAxis": {
"type": "category"
},
"series": [
{
"type": "bar",
"encode": {
"x": "amount",
"y": "product",
"tooltip": [
"product",
"score",
"amount"
]
}
}
],
"visualMap": {
"type": "continuous",
"min": 0,
"max": 100,
"dimension": 0,
"orient": "horizontal",
"bottom": 5,
"inRange": {
"color": [
"#d7da8b",
"#e15457"
]
}
}
}
},
{
"id": "dataset-linked",
"title": "折线和饼图共享并联动",
"option": {
"animation": false,
"legend": {
"bottom": 0
},
"tooltip": {
"trigger": "axis",
"showContent": false
},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期",
"第4期",
"第5期",
"第6期"
],
[
"HTML",
12,
24,
18,
31,
33,
35
],
[
"CSS",
16,
22,
29,
27,
29,
31
],
[
"JavaScript",
21,
17,
34,
30,
32,
34
],
[
"Web项目",
15,
26,
32,
38,
40,
42
]
]
},
"xAxis": {
"type": "category"
},
"yAxis": {},
"grid": {
"top": "55%",
"bottom": 70
},
"series": [
{
"id": "course-0",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-1",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-2",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-3",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "linked-pie",
"type": "pie",
"radius": "25%",
"center": [
"50%",
"25%"
],
"label": {
"formatter": "{b}: {@第1期} ({d}%)"
},
"encode": {
"itemName": "课程",
"value": "第1期",
"tooltip": "第1期"
}
}
]
},
"behavior": "linked"
}
]
};
export default async function run(){await mount(echarts,specification);}
查看独立实例 ↗ 在独立页面查看源码、运行环境与工程包
- 对应变体真实运行;其数据、图元、事件或状态独立记录
折线和饼图共享并联动:独立实例
展开查看收起
import * as echarts from 'echarts';
import {mount} from './lab.js';
// 本章独立配置和实际运行共用;数值均为自有虚构数据。
const specification = {
"key": "echarts-dataset",
"title": "ECharts dataset:行列、encode及图表联动",
"cases": [
{
"id": "dataset-matrix",
"title": "二维数组三系列",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期"
],
[
"HTML",
12,
24,
18
],
[
"CSS",
16,
22,
29
],
[
"JavaScript",
21,
17,
34
],
[
"Web项目",
15,
26,
32
]
]
},
"grid": {
"top": 65,
"bottom": 70,
"containLabel": true
},
"xAxis": {
"type": "category"
},
"yAxis": {
"type": "value"
},
"series": [
{
"id": "s0",
"type": "bar"
},
{
"id": "s1",
"type": "bar"
},
{
"id": "s2",
"type": "bar"
}
]
}
},
{
"id": "dataset-objects",
"title": "同数据对象数组",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
{
"课程": "HTML",
"第1期": 12,
"第2期": 24,
"第3期": 18
},
{
"课程": "CSS",
"第1期": 16,
"第2期": 22,
"第3期": 29
},
{
"课程": "JavaScript",
"第1期": 21,
"第2期": 17,
"第3期": 34
},
{
"课程": "Web项目",
"第1期": 15,
"第2期": 26,
"第3期": 32
}
],
"dimensions": [
"课程",
"第1期",
"第2期",
"第3期"
]
},
"grid": {
"top": 65,
"bottom": 70,
"containLabel": true
},
"xAxis": {
"type": "category"
},
"yAxis": {
"type": "value"
},
"series": [
{
"id": "s0",
"type": "bar"
},
{
"id": "s1",
"type": "bar"
},
{
"id": "s2",
"type": "bar"
}
]
}
},
{
"id": "dataset-row-column",
"title": "双网格行列对照",
"option": {
"animation": false,
"legend": {
"top": 10
},
"tooltip": {},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期",
"第4期"
],
[
"HTML",
12,
24,
18,
31
],
[
"CSS",
16,
22,
29,
27
],
[
"JavaScript",
21,
17,
34,
30
]
]
},
"grid": [
{
"top": 60,
"bottom": "55%",
"containLabel": true
},
{
"top": "60%",
"bottom": 40,
"containLabel": true
}
],
"xAxis": [
{
"type": "category",
"gridIndex": 0
},
{
"type": "category",
"gridIndex": 1
}
],
"yAxis": [
{
"gridIndex": 0
},
{
"gridIndex": 1
}
],
"series": [
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"seriesLayoutBy": "row",
"xAxisIndex": 0,
"yAxisIndex": 0
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
},
{
"type": "bar",
"xAxisIndex": 1,
"yAxisIndex": 1
}
]
}
},
{
"id": "dataset-encode",
"title": "显式水平编码",
"option": {
"animation": false,
"dataset": {
"source": [
[
"score",
"amount",
"product"
],
[
20,
120,
"阅读"
],
[
50,
240,
"实作"
],
[
80,
180,
"复习"
],
[
95,
310,
"调试"
],
[
10,
220,
"整理"
],
[
65,
270,
"回顾"
],
[
35,
160,
"表达"
],
[
72,
200,
"设计"
],
[
88,
260,
"验证"
]
]
},
"grid": {
"left": 90,
"right": 40,
"top": 55,
"bottom": 85
},
"xAxis": {
"type": "value",
"name": "amount"
},
"yAxis": {
"type": "category"
},
"series": [
{
"type": "bar",
"encode": {
"x": "amount",
"y": "product",
"tooltip": [
"product",
"score",
"amount"
]
}
}
]
}
},
{
"id": "dataset-four",
"title": "同一五维数据的四视图",
"option": {
"animation": false,
"dataset": {
"dimensions": [
"Income",
"Life Expectancy",
"Population",
"Country",
{
"name": "Year",
"type": "ordinal"
}
],
"source": [
[
"Income",
"Life Expectancy",
"Population",
"Country",
"Year"
],
[
10,
60,
20,
"地区甲",
2018
],
[
20,
65,
35,
"地区乙",
2019
],
[
30,
70,
15,
"地区丙",
2020
],
[
40,
75,
40,
"地区丁",
2021
]
]
},
"tooltip": {},
"grid": [
{
"left": 55,
"right": "55%",
"top": 45,
"bottom": "55%"
},
{
"left": "60%",
"right": 35,
"top": 45,
"bottom": "55%"
},
{
"left": 55,
"right": "55%",
"top": "60%",
"bottom": 45
},
{
"left": "60%",
"right": 35,
"top": "60%",
"bottom": 45
}
],
"xAxis": [
{
"type": "value",
"gridIndex": 0
},
{
"type": "category",
"gridIndex": 1
},
{
"type": "value",
"gridIndex": 2
},
{
"type": "value",
"gridIndex": 3
}
],
"yAxis": [
{
"type": "value",
"gridIndex": 0
},
{
"type": "value",
"gridIndex": 1
},
{
"type": "value",
"gridIndex": 2
},
{
"type": "value",
"gridIndex": 3
}
],
"series": [
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 0,
"yAxisIndex": 0,
"encode": {
"x": "Income",
"y": "Life Expectancy",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 1,
"yAxisIndex": 1,
"encode": {
"x": "Country",
"y": "Income",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 2,
"yAxisIndex": 2,
"encode": {
"x": "Income",
"y": "Population",
"tooltip": [
0,
1,
2,
3,
4
]
}
},
{
"type": "scatter",
"symbolSize": 9,
"xAxisIndex": 3,
"yAxisIndex": 3,
"encode": {
"x": "Life Expectancy",
"y": "Population",
"tooltip": [
0,
1,
2,
3,
4
]
}
}
]
}
},
{
"id": "dataset-color",
"title": "score颜色与amount坐标分开",
"option": {
"animation": false,
"dataset": {
"source": [
[
"score",
"amount",
"product"
],
[
20,
120,
"阅读"
],
[
50,
240,
"实作"
],
[
80,
180,
"复习"
],
[
95,
310,
"调试"
],
[
10,
220,
"整理"
],
[
65,
270,
"回顾"
],
[
35,
160,
"表达"
],
[
72,
200,
"设计"
],
[
88,
260,
"验证"
]
]
},
"grid": {
"left": 90,
"right": 40,
"top": 55,
"bottom": 85
},
"xAxis": {
"type": "value",
"name": "amount"
},
"yAxis": {
"type": "category"
},
"series": [
{
"type": "bar",
"encode": {
"x": "amount",
"y": "product",
"tooltip": [
"product",
"score",
"amount"
]
}
}
],
"visualMap": {
"type": "continuous",
"min": 0,
"max": 100,
"dimension": 0,
"orient": "horizontal",
"bottom": 5,
"inRange": {
"color": [
"#d7da8b",
"#e15457"
]
}
}
}
},
{
"id": "dataset-linked",
"title": "折线和饼图共享并联动",
"option": {
"animation": false,
"legend": {
"bottom": 0
},
"tooltip": {
"trigger": "axis",
"showContent": false
},
"dataset": {
"source": [
[
"课程",
"第1期",
"第2期",
"第3期",
"第4期",
"第5期",
"第6期"
],
[
"HTML",
12,
24,
18,
31,
33,
35
],
[
"CSS",
16,
22,
29,
27,
29,
31
],
[
"JavaScript",
21,
17,
34,
30,
32,
34
],
[
"Web项目",
15,
26,
32,
38,
40,
42
]
]
},
"xAxis": {
"type": "category"
},
"yAxis": {},
"grid": {
"top": "55%",
"bottom": 70
},
"series": [
{
"id": "course-0",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-1",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-2",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "course-3",
"type": "line",
"smooth": true,
"seriesLayoutBy": "row"
},
{
"id": "linked-pie",
"type": "pie",
"radius": "25%",
"center": [
"50%",
"25%"
],
"label": {
"formatter": "{b}: {@第1期} ({d}%)"
},
"encode": {
"itemName": "课程",
"value": "第1期",
"tooltip": "第1期"
}
}
]
},
"behavior": "linked"
}
]
};
export default async function run(){await mount(echarts,specification);}
查看独立实例 ↗ 在独立页面查看源码、运行环境与工程包
- 对应变体真实运行;其数据、图元、事件或状态独立记录
本章附件与实例包
常见错误与边界检查
- 只看option或标题而未核对真实数据、图元、状态。
- 旧版本、外部数据及未运行环境被误写成已完成。
技术规范与官方资料
练习与参考解答
查看参考解答
保持图表类型、轴、维度、数据和交互对应;完整来源事实、真人键盘/触屏/读屏及其他版本仍需独立复核。