【笔记】Echarts学习笔记
前言
Apache ECharts是一个使用TypeScript实现的可视化图表库,由Apache软件基金会提供,可以运行在主流桌面及移动浏览器上,包括Internet Explorer 8/9/10/11、Google Chrome、Firefox、Safari等,其底层依赖矢量图形库ZRender。
引入依赖
1 | <script src="https://unpkg.com/echarts@5/dist/echarts.min.js"></script> |
获取Echarts对象
width可以不指定,但是必须指定height
1 | <div id="chart" style="width: 600px; height: 400px;"></div> |
定义主题
dart:深色主题,缺省值为浅色主题
1 | const chart = echarts.init(document.getElementById("chart"), "dark"); |
指定渲染器
renderer:指定渲染器
canvas:缺省值,Canvas渲染器svg:SVG渲染器
1 | const chart = echarts.init(document.getElementById("chart"), null, { |
根据配置渲染图表
1 | const option = { |
定义数据
按顺序定义数据
1 | const option = { |
定义索引及数据
1 | const option = { |
定义数据对象
1 | const option = { |
1 | const option = { |
渲染地图
注册地图
1 | echarts.registerMap("China", { |
查看所有注册的地图
1 | const exist = echarts.getMap("China"); |
根据配置渲染地图
- 下载GeoJSON文件
阿里云数字可视化平台:https://datav.aliyun.com/portal/school/atlas/area_selector
1 | fetch("./中华人民共和国.geojson").then(res => res.json()).then(data => { |
1 | fetch("./中华人民共和国.geojson").then(res => res.json()).then(data => { |
与散点图配合
1 | fetch("./中华人民共和国.geojson").then(res => res.json()).then(data => { |
响应式
1 | <div id="chart" style="height: 400px;"></div> |
自动显示提示
seriesIndex:指定系列索引dataIndex:指定数据索引
1 | const chart = echarts.init(document.getElementById("chart")); |