码迷,mamicode.com
首页 > 其他好文 > 详细

vue echasrts的封装 (借鉴他人稍微改动)

时间:2020-01-15 09:55:28      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:ado   搜索引擎   data   component   font   polar   tick   export   value   

vue-echasrts的封装

废话不多说了

1. npm install echarts --save

2.组件代码

<template>
    <div class="echarts">
        <div id="echart"></div>
    </div>
</template>
 
<script>
import Echarts from ‘echarts‘
export default {
    data() {
        return{
            myChart: {}
        }
    },
    props: {
        echartObj: {
            type: Object,
            default: {
                 title: {
        text: ‘某站点用户访问来源‘,
        subtext: ‘纯属虚构‘,
        left: ‘center‘
    },
    tooltip: {
        trigger: ‘item‘,
        formatter: ‘{a} <br/>{b} : {c} ({d}%)‘
    },
    legend: {
        orient: ‘vertical‘,
        left: ‘left‘,
        data: [‘直接访问‘, ‘邮件营销‘, ‘联盟广告‘, ‘视频广告‘, ‘搜索引擎‘]
    },
    series: [
        {
            name: ‘访问来源‘,
            type: ‘pie‘,
            radius: ‘55%‘,
            center: [‘50%‘, ‘60%‘],
            data: [
                {value: 335, name: ‘直接访问‘},
                {value: 310, name: ‘邮件营销‘},
                {value: 234, name: ‘联盟广告‘},
                {value: 135, name: ‘视频广告‘},
                {value: 1548, name: ‘搜索引擎‘}
            ],
            emphasis: {
                itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: ‘rgba(0, 0, 0, 0.5)‘
                }
            }
        }
    ]
            }
        }
    },
    created() {
        this.$nextTick(()=> {
            this.loadEchart()
        })
    },
    mounted(){
        let _this = this;
        window.onresize = function() {
            _this.myChart.resize()
        }
    },
    methods: {
        loadEchart() {
            this.myChart = Echarts.init(document.getElementById("echart"));
            this.myChart.setOption(this.echartObj)
        }
    }
}
</script>
 
<style>
#echart {
    width: 50%;
    height: 300px;
}

</style>
 
3.组件的使用
 
<template>
  <div >
  
    <Eharts :echartObj="echartObj"></Eharts>
  </div>
  
</template>
 
<script>
import Eharts from ‘../components/echarts‘
 
export default {
 
  data() {
    return {
      echartObj:{
         angleAxis: {
    },
    radiusAxis: {
        type: ‘category‘,
        data: [‘周一‘, ‘周二‘, ‘周三‘, ‘周四‘],
        z: 10
    },
    polar: {
    },
    series: [{
        type: ‘bar‘,
        data: [1, 2, 3, 4],
        coordinateSystem: ‘polar‘,
        name: ‘A‘,
        stack: ‘a‘
    }, {
        type: ‘bar‘,
        data: [2, 4, 6, 8],
        coordinateSystem: ‘polar‘,
        name: ‘B‘,
        stack: ‘a‘
    }, {
        type: ‘bar‘,
        data: [1, 2, 3, 4],
        coordinateSystem: ‘polar‘,
        name: ‘C‘,
        stack: ‘a‘
    }],
    legend: {
        show: true,
        data: [‘A‘, ‘B‘, ‘C‘]
    }
      }
    }
  },
  mounted() {
  
  },
  components: {
    Eharts
  }
}
</script>
 
<style>
 
</style>
 
这样大部分的图标都可以用了
 使用时参照 echarts官网 修改echartObj

 

vue echasrts的封装 (借鉴他人稍微改动)

标签:ado   搜索引擎   data   component   font   polar   tick   export   value   

原文地址:https://www.cnblogs.com/zhanghongb/p/12194778.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!