mpvue——动态渲染echarts图表

时间:2022-09-07 14:21:53

前言

使用mpvue-echarts来写图表,那个F2再提醒自己下要踩坑不能忘记。遇到了一个问题就是数据不能动态的去渲染,这个其实官方给了我们对应的方法

懒加载

代码

修改了调用initChart()的位置

<!--
* @Author: wangyang
* @LastEditors: wangyang
* @Description: file content
* @Date: 2019-04-08 16:34:52
* @LastEditTime: 2019-04-10 14:15:29
-->
<template>
<div class="container">
<!-- <button @click="initChart">初始化</button> -->
<div class="wrap">
<mpvue-echarts lazyLoad :echarts="echarts" :onInit="handleInit" ref="echarts" />
</div>
</div>
</template> <script>
import * as echarts from 'echarts/dist/echarts.simple.min'
import mpvueEcharts from 'mpvue-echarts'
let chart = null
export default {
data () {
return {
option: null,
echarts,
share:[]
}
},
components: {
mpvueEcharts
},
mounted(){
this.query();
},
methods: {
initChart () {
this.option = {
backgroundColor: '#fff',
color: ['#67E0E3'], legend: {
data: [ '访问人数'],
top:'top'
},
grid: {
containLabel: true
},
xAxis: {
type: 'category',
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
},
yAxis: {
x: 'center',
type: 'value',
splitLine: {
lineStyle: {
type: 'dashed'
}
}
},
series: [
{
name: '访问人数',
type: 'line',
smooth: false,
label: {
normal: {
show: true,
padding:[0,7,0,0]
}
},
data: this.share
}]
}
this.$refs.echarts.init()
},
handleInit (canvas, width, height) {
chart = echarts.init(canvas, null, {
width: width,
height: height
})
canvas.setChart(chart)
chart.setOption(this.option)
return chart
},
query() {
const that = this;
that.http({
url: 'Employee/statistic',
data:{
wid:2,
type:1,
uid:100007
}
}).then(res =>{
if (res.status) {
this.share = res.data.share_count;
this.initChart();
}
})
},
},
onShareAppMessage () {}
}
</script> <style scoped>
.wrap {
width: 100%;
height: 300px;
}
</style>

mpvue——动态渲染echarts图表的更多相关文章

  1. Vue自定义标签页,并且在其中渲染Echarts图表

    目录 一.需求说明 二.标签页功能实现 一.需求说明 1.点击标签按钮切换不同的echarts图表,考虑用Ant Design Vue,但是其样式无法自定义 2.div的整体布局样式使用tailwin ...

  2. react 动态渲染echarts折线图,鼠标放大缩小

    //折线图组件import React,{Component} from 'react'; import ReactEcharts from 'echarts-for-react'; class Ec ...

  3. 小程序mpvue中动态切换echarts图表

    如果你用mpvue,而且还想用echarts,那么这个包你可以以来一下 https://github.com/F-loat/mpvue-echarts 考虑到多个页面都休要用,所以抽出来作为一个组件, ...

  4. vue学习【二】vue结合axios动态引用echarts

    大家好,我是一叶,本篇是vue学习的第二篇,本篇将要讲述vue结合axios动态引用echarts. 在vue中,异步刷新使用的是axios,类似于大家常用的ajax,其实axios已经是vue的第二 ...

  5. echarts在miniUI和ajax下动态渲染数据

    <script src="echarts.js"></script> <script src="jquery-3.3.1.min.js&qu ...

  6. 使用Python的Flask框架,结合Highchart,动态渲染图表&lpar;Ajax 请求数据接口&rpar;

    参考链接:https://www.highcharts.com.cn/docs/ajax 参考链接中的示例代码是使用php写的,这里改用python写. 需要注意的地方: 1.接口返回的数据格式,这个 ...

  7. 使用Python的Flask框架,结合Highchart,动态渲染图表

    服务端动态渲染图表 参考文章链接:https://www.highcharts.com.cn/docs/dynamic-produce-html-page 参考文章是使用php写的,我这边改用pyth ...

  8. mui在tab选项卡中echarts图表不能动态随页面变化大小 只能固定大小

    在mui tab选项卡中一直都不能让echarts动态变化大小 只能固定大小来展示图表,网上说的window.onresize = mycharts.resize;方法根本就没有效果,后面在https ...

  9. Echarts使用及动态加载图表数据

    Echarts使用及动态加载图表数据 官网:http://echarts.baidu.com/ 1.文档 2.实例 名词: 1.统计维度(说明数据) 维度就是统计致力于建立一个基于多方位统计(时间.地 ...

随机推荐

  1. Circuit Breaker Pattern(断路器模式)

    Handle faults that may take a variable amount of time to rectify when connecting to a remote service ...

  2. 不可或缺 Windows Native &lpar;11&rpar; - C&plus;&plus;&colon; hello c&plus;&plus;&comma; C&plus;&plus; 与 C语言的区别小介

    [源码下载] 不可或缺 Windows Native (11) - C++: hello c++, C++ 与 C语言的区别小介 作者:webabcd 介绍不可或缺 Windows Native 之 ...

  3. 重学C语言 -- printf,scanf

     printf();    用来显示格式串的内容          注意: 参数不可以换行,否则会出一个警告.       格式串中占位符比表达式数量多     会显示一个无意义值 格式串中占位符比表 ...

  4. 王立平-Android中对图像进行Base64编码

    // ------------------base64-------------------// public String bitmaptoString(Bitmap bitmap) { // 将B ...

  5. 三种客户端访问wcf服务端的方法 C&num;

    原文 http://blog.csdn.net/zlj002/article/details/7914556 string jsonstr = String.Empty; string url = & ...

  6. POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)

    Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 30281   Accepted: 9124 Des ...

  7. &lbrack;译&rsqb;Selenium Python文档:六、页面对象

    本章是介绍页面对象设计模式的教程.一个页面对象代表了web应用用户接口的一片区域,你的测试代码将与之交互的. 使用页面对象模式的好处: 可以创建在多个测试样例中都可使用的可重用代码 减少重复性代码 如 ...

  8. 错误代码是1130,ERROR 1130&colon; Host xxx&period;xxx&period;xxx&period;xxx is not allowed to connect to this MySQL server 是无法给远程连接的用户权限问题

    错误代码是1130,ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to connect to this MySQL server 是无法给远程连接的用 ...

  9. IntelliJ IDEA 调试&lpar;debug&rpar;时非常慢的原因

    IntelliJ  IDEA 开发时,发现有时Debug时tomcat启动的非常慢,需要等待超过20分钟,但有时就很快,经查找发现是断点设置问题, 若断点设置在方法名上,debug时就会非常慢, 如图 ...

  10. vue pc端网站项目开发坑点与难度记录

    背景 在一pc端的web项目里,由于某些特性需要由动态语言处理,所以只在有需要使用vue来处理数据的页面,直接引入vue.js来处理.由于刚开始并没有打算使用前端来渲染数据和处理交互,所以使用了一些非 ...