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>
    

      

    .

     

  • 相关阅读:
    HDU2034 人见人爱 A
    二分查找
    利用向量积(叉积)计算三角形(多边形)的面积
    找出能被5或6整除,但是不能被两者同时整除的数 Exercise05_11
    找出分数最高的前两个学生 Exercise05_09
    金融应用,计算将来的学费 Exercise05_07
    千克与磅之间的转换 Exercise05_05
    将千克转换成磅 Exercise05_03
    统计正数和负数的个数,然后计算这些数的平均值 Exercise05_01
    回文数
  • 原文地址:https://www.cnblogs.com/feifan1/p/12797496.html
Copyright © 2011-2022 走看看