zoukankan      html  css  js  c++  java
  • vue中使用v-echars

    1.安装插件

    npm i vue-echarts echars lodash
    

    2.创建文件并引入

    import isEmpty from 'lodash/isEmpty'
    import isArray from 'lodash/isArray'
    import compact from 'lodash/compact'
    import ECharts from 'vue-echarts'
    import 'echarts/lib/chart/bar' // 柱状图
    import 'echarts/lib/chart/line' // 线图
    import 'echarts/lib/chart/pie' // 饼转图
    import 'echarts/lib/chart/custom' // 饼转图
    import 'echarts/lib/chart/scatter' // 散点图
    import 'echarts/lib/chart/tree' // 树图
    import 'echarts/lib/chart/treemap'
    import 'echarts/lib/chart/boxplot' // 箱形图、盒须图、盒式图、盒状图、箱线图
    import 'echarts/lib/chart/candlestick' // k线图
    import 'echarts/lib/chart/map' // 地图
    import 'echarts/lib/chart/pictorialBar' // 人物
    import 'echarts/lib/component/title'
    import 'echarts/lib/component/legend'
    import 'echarts/lib/component/tooltip'
    import 'echarts/lib/component/toolbox'
    import 'echarts/lib/component/dataZoom'
    import 'echarts/lib/component/markLine'
    import 'echarts/lib/component/markPoint'
    import 'echarts/lib/component/visualMap'
    import 'echarts/lib/component/timeline'
    
    import theme from './themJson/compact.json' //默认样式文件
    

     3. 使用echars

     <e-charts
          ref="echarts"
          :options="options"
          theme="compact"
          autoresize
          style="100%;height:100%"
        />
    

     4

    ECharts.registerTheme('compact', theme)
    

     5.js部分

    export default {
      components: { ECharts },
      props: {
        option: {
          type: Object,
          default: () => {}
        }
      },
      data() {
        return {
        }
      },
      computed: {
        options: function() {
          return this.option
        }
      },
      watch: {
        option: {
          handler: function(val, oldVal) {
            this.visible = true
            const { dataset, series } = val
            if (this.notEmptyData(series)) {
              this.visible = true
            } else {
              this.visible = this.notEmptyData(dataset, 'source')
            }
          },
          deep: true,
          immediate: true
        }
      },
      methods: {
        notEmptyData(data, unit = 'data') {
          let flag = false
          if (!isEmpty(data)) {
            if (isArray(data)) {
              const arr = compact(data)
              const index = arr.findIndex(item => !isEmpty(item[unit]))
              flag = index > -1
            } else {
              flag = !isEmpty(data[unit])
            }
          }
          return flag
        }
      }
    }
    </script>
    

      

    .

     

  • 相关阅读:
    Mysql数据库基本操作
    Entity Framework 实践系列 —— 搞好关系 单相思(单向一对一,onetoone)
    ADO.NET最佳实践
    C++试题1
    SQL操作(初级、中级、高级)
    存储过程入门与提高
    数据库学习笔记
    触发器设计技巧与实例
    UML在关系型数据库设计中的应用
    数据库设计的一些构想
  • 原文地址:https://www.cnblogs.com/feifan1/p/12797496.html
Copyright © 2011-2022 走看看