Vue+Echarts實(shí)現(xiàn)一個(gè)餅狀圖

在jQuery里面,實(shí)現(xiàn)一個(gè)折線圖,【前端統(tǒng)計(jì)圖】echarts實(shí)現(xiàn)單條折線圖
http://m.itdecent.cn/p/0354a4f8c563

現(xiàn)在要實(shí)現(xiàn),Vue+Echarts實(shí)現(xiàn)一個(gè)折線圖,打開之前的mint項(xiàng)目:

1:在項(xiàng)目里面安裝echarts

cnpm install echarts --s

2:在需要用圖表的地方引入

import echarts from 'echarts'

3:打開my.vue
繼續(xù)寫代碼,代碼如下:

<template>
  <!--為echarts準(zhǔn)備一個(gè)具備大小的容器dom-->
  <div id="main" style="width: 600px;height: 400px;"></div>
</template>
<script>
  import echarts from 'echarts'
    export default {
        name: '',
        data () {
            return {
                charts: '',
                opinion:['男','女'],
                opinionData:[
                  {value:335, name:'男'},
                  {value:310, name:'女'},
                
                ]
            }
        },
        methods:{
            drawPie(id){
               this.charts = echarts.init(document.getElementById(id))
               this.charts.setOption({
                 tooltip: {
                   trigger: 'item',
                  
                 },
                 legend: {
                   orient: 'vertical',
                   x: 'left',
                   data:this.opinion
                 },
                 series: [
                   {
                     name:'性別',
                     type:'pie',
                     radius:['50%','70%'],
                     avoidLabelOverlap: false,
                     label: {
                       normal: {
                         show: false,
                         position: 'center'
                       },
                       emphasis: {
                         show: true,
                         textStyle: {
                           fontSize: '30',
                           fontWeight: 'blod'
                         }
                       }
                     },
                     labelLine: {
                       normal: {
                         show: false
                       }
                     },
                     data:this.opinionData
                   }
                 ]
               })
            }
        },
      //調(diào)用
        mounted(){
            this.$nextTick(function() {
                this.drawPie('main')
            })
        }
    }
</script>
<style scoped>
    * {
        margin: 0;
        padding: 0;
        list-style: none;
    }
</style>

這個(gè)時(shí)候,可以看到,加載出的餅狀圖了,后面可以繼續(xù)進(jìn)行完善。



原文作者:祈澈姑娘 技術(shù)博客:http://m.itdecent.cn/u/05f416aefbe1
90后前端妹子,愛編程,愛運(yùn)營(yíng),文藝與代碼齊飛,魅力與智慧共存的程序媛一枚。
堅(jiān)持總結(jié)工作中遇到的技術(shù)問題,堅(jiān)持記錄工作中所所思所見,對(duì)于博客上面有不會(huì)的問題,歡迎加入編程微刊主頁qq群。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容