×

分享一个VUE小应用:Echarts利用watch做动态数据渲染操作

作者:andy0012021.02.05来源:Web前端之家浏览:6672评论:0
关键词:jsvue

分享一个VUE小应用:Echarts利用watch做动态数据渲染操作。

首先安装引入Echarts,我是直接把Echarts挂到VUE全局变量上了。

//引入echarts
import Vue from 'vue';
import echarts from 'echarts';
Vue.prototype.$echarts = echarts;

//模板
<template>
 <div>
  <div ref="chart_wrap"></div>
 </div>
</template>
<script>
export default {
 name: "demo",
 computed: {},
 data() {
  return {
   seriesData: []
  };
 },
 created() {},
 mounted() {
  this.initCharts();
  setTimeout(() => {
   this.seriesData.push({
    name: "销量",
    type: "bar",
    data: [5, 20, 36, 10, 10, 20]
   });
  }, 5000);
 },
 watch: {
  seriesData(val, oldVal) {
   console.log(1111, val, oldVal);
   this.setOptions(val);
  }
 },
 methods: {
  initCharts() {
   this.chart = this.$echarts.init(this.$refs.chart_wrap);
   this.setOptions();
  },
  setOptions(series) {
   console.log(22222,this.chart,series);
   this.chart.setOption({
    title: {
     text: "ECharts 入门示例"
    },
    tooltip: {},
    legend: {
     data: ["销量"]
    },
    xAxis: {
     data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    },
    yAxis: {},
    series: series
   });
  }
 }
};
</script>
<style rel="stylesheet/scss" scoped>
.chart_wrap {
 height: 400px;
}
</style>

您的支持是我们创作的动力!
温馨提示:本文作者系 ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://www.jiangweishan.com/article/js20210205a1.html

网友评论文明上网理性发言 已有0人参与

发表评论: