• Vue -- 数据更新echarts表格不更新问题


    项目使用的是 vue-element-admin

    <template>
      <div>
        <div ref="line" :class="className" :style="{height:height,width}" />
      </div>
    </template>
    <script>
    import echarts from 'echarts'
    require('echarts/theme/macarons') // echarts theme
    import resize from '../../mixins/resize'
    export default {
      mixins: [resize],
      props: {
        className: {
          type: String,
          default: "chart"
        },
         {
          type: String,
          default: "100%"
        },
        height: {
          type: String,
          default: "350px"
        },
        autoResize: {
          type: Boolean,
          default: true
        },
        lineChartData: {
          type: Object,
          required: true
        }
      },
      data() {
        return {
          chart: null
        };
      },
      mounted() {
        this.$nextTick(() => {
          this.initChart()
        })
      },
      watch: {
        lineChartData: {
          deep: true,
          handler(val) {
            this.setOptions(val);
          }
        }
      },
      beforeDestroy() {
        if (!this.chart) {
          return;
        }
        this.chart.dispose();
        this.chart = null;
      },
      methods: {
        initChart() {
          this.chart = echarts.init(this.$refs.line, 'macarons')
          // this.chart = echarts.init(this.$el, "macarons");
          this.setOptions(this.lineChartData)
        },
        setOptions({ data, value, name } = {}) {
          var max = value && value.length ? null : 100;
          this.chart.setOption({
            xAxis: {
              data: data
              // boundaryGap: false,
              // axisTick: {
              //   show: false
              // }
            },
            grid: {
              left: 10,
              right: '3%',
              bottom: 20,
              top: 30,
              containLabel: true
            },
            tooltip: {
              trigger: 'axis',
              axisPointer: {
                type: 'cross'
              },
              padding: [5, 10]
            },
             yAxis: {
              max: max,
              minInterval: 1,
              axisTick: {
                show: false
              }
            },
            legend: {
              data: [name]
            },
            series: [{
              name: name,
              itemStyle: {
                normal: {
                  color: '#FF005A',
                  lineStyle: {
                    color: '#FF005A',
                     2
                  }
                }
              },
              smooth: true,
              type: 'line',
              data: value,
              animationDuration: 2800,
              animationEasing: 'cubicInOut'
            }]
          })
        }
      }
    }
    </script>
    

    有些数据我的项目是一起给的,切换自己做的处理,如果不能直接赋值就使用this.$set设置data值

    formatTab() {
          // this.lineChartData.name = "收藏数";
          this.$set(this.lineChartData, 'name', "收藏数" )
          var name = "totalCollectNum";
          switch (this.form.radio2) {
            case "1":
              // this.lineChartData.name = "收藏数";
              this.$set(this.lineChartData, 'name', "收藏数" )
              name = "totalCollectNum";
              break;
            case "2":
              // this.lineChartData.name = "点赞数";
              this.$set(this.lineChartData, 'name', "点赞数" )
              name = "totalLikeNum";
              break;
            case "3":
              // this.lineChartData.name = "阅读数";
              this.$set(this.lineChartData, 'name', "阅读数" )
              name = "totalReadNum";
              break;
            default:
              // this.lineChartData.name = "收藏数";
              this.$set(this.lineChartData, 'name', "收藏数" )
              name = "totalCollectNum";
          }
          var value = [];
          var data = [];
          var tableData = this.list;
          for (var i = 0; i < tableData.length; i++) {
            // data.push( this.parseTime(new Date(tableData[i].recordDate), "{y}-{m}-{d}")) // 横坐标
            data.push(tableData[i].recordDate); // 横坐标
            value.push(tableData[i][name]);
          }
          // this.lineChartData.value = value;
          // this.lineChartData.data = data;
          this.$set(this.lineChartData, 'data', data )
          this.$set(this.lineChartData, 'value', value )
        },
    
  • 相关阅读:
    C++中函数模板template的使用
    C++中模板template和类class的结合使用
    Python中shuffle函数
    Python中利用tkinter模块构建图形用户界面GUI
    Python中怎样初始化一个类类class?
    Python中字典的has_key方法在3.4版本中改为in
    Python中怎样对数据集整体进行映射转换类型
    matlab中怎样对矩阵的某一列进行排序而使得其他列对应移动??
    Python中怎样使用shape计算矩阵的行和列
    27.反射2.md
  • 原文地址:https://www.cnblogs.com/lisaShare/p/13458750.html
Copyright © 2020-2023  润新知