mpvue——引入echarts图表
安装
mpvue-echarts的github地址
https://github.com/F-loat/mpvue-echarts
$ cnpm install mpvue-echarts
$ cnpm install echarts
DEMO
复制粘贴后即可看到效果
<!--
* @Author: wangyang
* @LastEditors: wangyang
* @Description: file content
* @Date: -- ::
* @LastEditTime: -- ::
-->
<template>
<div class="wrap">
<mpvue-echarts :echarts="echarts" :onInit="ecBarInit" canvasId="bar" />
<mpvue-echarts :echarts="echarts" :onInit="ecScatterInit" canvasId="scatter" />
</div>
</template> <script>
import * as echarts from 'echarts/dist/echarts.min'
import mpvueEcharts from 'mpvue-echarts'
let barChart, scatterChart
function getBarOption () {
return {
color: ['#37a2da', '#32c5e9', '#67e0e3'],
tooltip: {
trigger: 'axis',
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'line' // 默认为直线,可选为:'line' | 'shadow'
}
},
legend: {
data: ['热度', '正面', '负面']
},
grid: {
left: ,
right: ,
bottom: ,
top: ,
containLabel: true
},
xAxis: [
{
type: 'value',
axisLine: {
lineStyle: {
color: '#999'
}
},
axisLabel: {
color: '#666'
}
}
],
yAxis: [
{
type: 'category',
axisTick: { show: false },
data: ['汽车之家', '今日头条', '百度贴吧', '一点资讯', '微信', '微博', '知乎'],
axisLine: {
lineStyle: {
color: '#999'
}
},
axisLabel: {
color: '#666'
}
}
],
series: [
{
name: '热度',
type: 'bar',
label: {
normal: {
show: true,
position: 'inside'
}
},
data: [, , , , , , ]
},
{
name: '正面',
type: 'bar',
stack: '总量',
label: {
normal: {
show: true
}
},
data: [, , , , , , ]
},
{
name: '负面',
type: 'bar',
stack: '总量',
label: {
normal: {
show: true,
position: 'left'
}
},
data: [-, -, -, -, -, -, -]
}
]
}
}
function getScatterOption () {
var data = []
var data2 = []
for (var i = ; i < ; i++) {
data.push(
[
Math.round(Math.random() * ),
Math.round(Math.random() * ),
Math.round(Math.random() * )
]
)
data2.push(
[
Math.round(Math.random() * ),
Math.round(Math.random() * ),
Math.round(Math.random() * )
]
)
}
var axisCommon = {
axisLabel: {
textStyle: {
color: '#C8C8C8'
}
},
axisTick: {
lineStyle: {
color: '#fff'
}
},
axisLine: {
lineStyle: {
color: '#C8C8C8'
}
},
splitLine: {
lineStyle: {
color: '#C8C8C8',
type: 'solid'
}
}
}
return {
color: ['#FF7070', '#60B6E3'],
backgroundColor: '#eee',
xAxis: axisCommon,
yAxis: axisCommon,
legend: {
data: ['aaaa', 'bbbb']
},
visualMap: {
show: false,
max: ,
inRange: {
symbolSize: [, ]
}
},
series: [{
type: 'scatter',
name: 'aaaa',
data: data
},
{
name: 'bbbb',
type: 'scatter',
data: data2
}
],
animationDelay: function (idx) {
return idx *
},
animationEasing: 'elasticOut'
}
}
export default {
data () {
return {
echarts,
ecBarInit: function (canvas, width, height) {
barChart = echarts.init(canvas, null, {
width: width,
height: height
})
canvas.setChart(barChart)
barChart.setOption(getBarOption())
return barChart
},
ecScatterInit: function (canvas, width, height) {
scatterChart = echarts.init(canvas, null, {
width: width,
height: height
})
canvas.setChart(scatterChart)
scatterChart.setOption(getScatterOption())
return scatterChart
}
}
},
components: {
mpvueEcharts
},
onShareAppMessage () {}
}
</script> <style scoped>
.wrap {
width: %;
height: 400px;
}
</style>
效果图

折线图
<template>
<div class="container">
<div class="wrap">
<mpvue-echarts :echarts="echarts" :onInit="onInit" />
</div>
</div>
</template> <script>
import * as echarts from 'echarts/dist/echarts.simple.min'
import mpvueEcharts from 'mpvue-echarts'
function initChart (canvas, width, height) {
const chart = echarts.init(canvas, null, {
width: width,
height: height
})
canvas.setChart(chart)
var option = {
backgroundColor: '#fff',
color: ['#37A2DA', '#67E0E3'], legend: {
data: ['A', 'B']
},
grid: {
containLabel: true
},
xAxis: {
type: 'category',
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
},
yAxis: {
x: 'center',
type: 'value',
splitLine: {
lineStyle: {
type: 'dashed'
}
}
},
series: [{
name: 'A',
type: 'line',
smooth: true,
data: [18, 36, 65, 30, 78, 40, 33]
}, {
name: 'B',
type: 'line',
smooth: true,
data: [12, 50, 51, 35, 70, 30, 20]
}]
}
chart.setOption(option)
return chart
}
export default {
data () {
return {
echarts,
onInit: initChart
}
},
components: {
mpvueEcharts
},
onShareAppMessage () {}
}
</script> <style scoped>
.wrap {
width: 100%;
height: 300px;
}
</style>
mpvue中引入使用echarts就是这么简单且github的仓库中大部分的demo都可以直接修改使用比较方便吧,主要是之前使用过echarts所以更改起来也非常的舒服!
mpvue——引入echarts图表的更多相关文章
- vue 引入 echarts 图表 并且展示柱状图
npm i echarts -S 下载 echarts 图表 mian.js 文件 引入图表并且全局挂载 //echarts 图表 import echarts from 'echarts' Vue. ...
- mpvue——引入echarts打包vendor过大
前言 有一个项目需要引入图表,当时有两种选择一种是mpvue-echarts,一种是F2,而我经过踩坑之后依然决然的选择了mpvue-echarts,简单快捷容易上手,主要之前用过比较熟悉. 问题 | ...
- mpvue——引入antv-F2图表
踩坑中~ 官方文档 https://www.yuque.com/antv/f2/intro 毕竟不像echarts接触过,所以还是先看看文档较好 github https://github.com/s ...
- 在vue页面引入echarts,图表的数据来自数据库 springboot+mybatis+vue+elementui+echarts实现图表的制作
文章目录 1.实现的效果 2.前端代码 3.后端controller代码 4.servie层代码 5.serviceImpl层代码 6.mapper层代码 7.xml中的sql语句 8.遇到的问题 8 ...
- 转:ECharts图表组件之简单关系图:如何轻松实现另类站点地图且扩展节点属性实现点击节点页面跳转
站点地图不外乎就是罗列一个网站的层次结构,提炼地讲就是一个关系结构图.那么我们如何巧用ECharts图表组件内的简单关系结构图来实现一个站点的地图结构呢?另外如何点击某个节点的时候实现页面跳转呢? 针 ...
- vue引入echarts、找不到的图表引入方法、图表中的点击事件
1.在vue-cli项目中添加webpack配置,本文引入的最新版本.在 3.1.1 版本之前 ECharts 在 npm 上的 package 是非官方维护的,从 3.1.1 开始由官方 EFE 维 ...
- mpvue 使用echarts动态绘制图表(数据改变重新渲染图表)
最近在公司开发一款微信小程序,按照客户需求用饼状图显示当前设备状态(开机.故障.关机),于是就在网上寻找各种资料,找了很多mpvue使用关于echarts绘制图表,最终功夫不负有心人,找到一篇关于mp ...
- mpvue中按需引入echarts
大家都知道小程序文件大小不能超过2M, 在项目中引入echarts后,文件大小远远超出2M了.因为echarts文件默认是包含所有图表代码的,所以文件体积会比较大.解决办法如下: 安装 首先我们先安装 ...
- AngularJS引入Echarts的Demo
最近要用到图表展示,想了想,还是首选Echarts,HighCharts和D3.js备用吧, 而项目中也用到了AngularJS,所以需要把Echarts引入到AngularJs中一起使用, 试了试, ...
随机推荐
- wordcloud2.js
https://blogs.msdn.microsoft.com/dotnet/2019/01/10/announcing-ml-net-0-9-machine-learning-for-net/ h ...
- Adaptive Placeholders
https://wisdmlabs.com/blog/create-adaptive-placeholders-using-css/ https://circleci.com/blog/adaptiv ...
- 36.Odoo产品分析 (四) – 工具板块(6) – 午餐管理(2)
查看Odoo产品分析系列--目录 接上一篇Odoo产品分析 (四) – 工具板块(6) – 午餐管理(1) 4 查看订单 点击"之前的订单",可以看到刚才的订单信息: 点击右边的 ...
- 推荐一款MongoDB的客户端管理工具--nosqlbooster
今天给大家推荐一款MongoDB的客户端工具--nosqlbooster,这个也是我工作中一直使用的连接管理MongoDB的工具.这个工具还有个曾用名--mongobooster.nosqlboost ...
- 使用VBScript 脚本 开机播放声音
前言:环境Window 10 第一步写一个 VBScript 脚本 新建一个文本文档,将下面的代码复制到文本文档中,Ctrl+S保存 将文本文档的.txt 后缀 改为.vbs即可 最后,双击这个 vb ...
- c/c++ 继承与多态 子类隐藏父类的同名非虚函数
问题1:若类A里有公有成员方法int fcn(),类B公有继承类A,并类B里有公有成员方法int fcn(int),可以在用户代码里,用类B的对象调用类A的int fcn()吗?? 不可以,编译出错, ...
- Server 2008 R2多用户远程桌面连接授权,解决120天过期问题
在工作中,我们往往需要远程服务器,经常会遇到以下这两个麻烦事. 一.远程桌面的连接数限制,超出系统就会提示超过连接数. 二.远程桌面连接时,同一个用户不能同时远程2个桌面连接. ----------- ...
- java反射(java.lang.reflect)---java.lang.reflect.Modifier中状态码
1. 详情请看jvm(虚拟机)规范 java.lang.reflect.Modifier public static final int ABSTRACT 1024 public static fin ...
- mn
http://image.uczzd.cn/10129986679866437816.jpg?id=0&from=export https://www.cnblogs.com/ityoukno ...
- AQS框架源码分析-AbstractQueuedSynchronizer
前言:AQS框架在J.U.C中的地位不言而喻,可以说没有AQS就没有J.U.C包,可见其重要性,因此有必要对其原理进行详细深入的理解. 1.AQS是什么 在深入AQS之前,首先我们要搞清楚什么是AQS ...