ECharts
ECharts的作用
ECharts,一个使用 JavaScript 实现的开源可视化库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大部分浏览器(IE8/9/10/11,Chrome,Firefox,Safari等),底层依赖矢量图形库 ZRender,提供直观,交互丰富,可高度个性化定制的数据可视化图表。
ECharts官网地址:https://echarts.apache.org/zh/index.html
ECharts的获取方式有很多种 比如:
-
从 Apache ECharts (incubating) 官网下载界面 获取官方源码包后构建。
-
在 ECharts 的 GitHub 获取。
-
通过 npm 获取 echarts,
npm install echarts --save -
通过 jsDelivr 等 CDN 引入
最常用的就是通过npm获取
然后简单演示一下在vue中是如何使用ECharts的 要展示的是一个堆叠区域图
<!-- 为Echarts准备一个Dom --> <div id="main" style="width: 750px;height:400px;"></div>
JS部分
<script> // 1.导入echarts import echarts from 'echarts' //这里引用了之前封装好的接口 import {getEChartsDta} from '@/http/api' import _ from 'lodash' export default { data () { return { // 需要合并的数据 options: { title: { text: '用户来源' }, tooltip: { trigger: 'axis', axisPointer: { type: 'cross', label: { backgroundColor: '#E9EEF3' } } }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, xAxis: [ { boundaryGap: false } ], yAxis: [ { type: 'value' } ] } } }, mounted () { // 3.基于准备好的dom,初始化echarts实例 var myChart = echarts.init(document.getElementById('main')) const { data: res } = await getEChartsDta() // 数据合并 const result = _.merge(res.data, this.options) // 5.展示数据 myChart.setOption(result) } } </script>
最后显示的大概就是这个样子


浙公网安备 33010602011771号