vue组建之——简单饼状图

父组件:

<chartPie :pieChartData="charData"></chartPie>

参数:

vue.cardData_1= {

  class: 'number_of_calls',

  name: '拨打数量',

  data: [

    {key: '拨打数量', value: 30},

    {key: '正在进行', value: 5}

]

};


子组件:


<template>

  <div class="pieChart">

    <p class="chartName">{{pieChartData.name}}</p>

    <div :id="pieChartData.id" ref="pieEchart" class="chart"></div>

  </div>

</template>

<script>

  import Echartfrom 'echarts'

  import {mapState} from 'vuex'

  export default {

    title: '用户分析-- 饼状图',

    name: "pieChart",

    computed: {

      ...mapState({

        // chartData: state => state.vux.chartData

      })

    },

    components: {},

    props: {

      pieChartData: {

        type: Object,

        default: () => ({

          // 唯一ID

          id: 'defaultChart',

          // Chart的title

          name: '···加载中···',

          // legend的Name

          legendData: ['加载中···'],

          // 外圈title

          seriesOuterRingName: '加载中···',

          // 外圈值

          seriesOuterRingData:[{value: '0', name: '加载中···'}],

        })

}

    },

    data() {

      return {}

    },

    created() {

      let vue = this;

    },

    mounted() {

      let vue = this;

      vue.initChart();

      // vue.$watch('chartData', () =>{

//  vue.initChart();

// })

    },

    methods: {

      // 初始化Chart

      initChart() {

        let vue = this;

        vue.chart= Echart.init(vue.$refs.pieEchart);

        vue.chart.setOption({

          color: ['#0962F4','#FF4935','#2EDCFF','#409EFF'],

          tooltip: {

            trigger: 'item',

            formatter: "{a}
{b}: {c}%"

          },

          legend: {

            orient: 'horizontal',

            x: 'left',

            // top: '60%',

// width: '80px',

            data: vue.pieChartData.legendData

},

          series: {

            name: vue.pieChartData.seriesOuterRingName,

            type:'pie',

            radius: ['40%', '60%'],

            label: {

              normal: {

                // formatter: '{a|{a}}{abg|}\n{hr|}\n  {b|{b}:}{c}  {per|{d}%}',

// formatter: '{c}  {per|{d}%}',

                formatter: '{per|{c}%}',

                backgroundColor: '#eee',

                borderColor: '#CCC',

                borderWidth: 1,

                borderRadius: 4,

                padding: [5, 7],

                rich: {

                  per: {

                    color: '#eee',

                    backgroundColor: '#334455',

                    padding: [2, 1],

                    borderRadius: 2

                  }

}

}

            },

            data: vue.pieChartData.seriesOuterRingData

}

})

}

}

}

</script>

<style scoped lang="less">

  .pieChart{

    width:100%;

    height:180px;

    padding-bottom:20px;

    .chart{height:100%;}

    .chartName{font-size:15px;font-weight:bold;padding:10px 5px;};

  }

</style>


11980476-77415de8d5adf24b.png
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue3中使用echarts饼状图可以通过以下步骤实现: 1. 首先,确保你已经安装了echarts和vue-echarts插件。可以通过npm或yarn进行安装。 2. 在你的Vue组件中,引入echarts和vue-echarts插件。 ```javascript import * as echarts from 'echarts'; import ECharts from 'vue-echarts'; ``` 3. 在template中,使用ECharts组件,并设置图表的类型为饼状图。 ```html <template> <div> <e-charts :options="chartOptions" :auto-resize="true"></e-charts> </div> </template> ``` 4. 在data中定义chartOptions对象,并设置饼状图的配置选项,如数据和样式。 ```javascript data() { return { chartOptions: { series: [ { type: 'pie', data: [ { value: 335, name: 'Category 1' }, { value: 310, name: 'Category 2' }, { value: 234, name: 'Category 3' }, { value: 135, name: 'Category 4' }, { value: 1548, name: 'Category 5' }, ], }, ], }, }; }, ``` 5. 在mounted生命周期钩子中,初始化echarts实例,并将其绑定到ECharts组件上。 ```javascript mounted() { this.$nextTick(() => { const chart = echarts.init(this.$refs.chart); this.$refs.chart.echarts = chart; }); }, ``` 6. 最后,在需要的地方使用ECharts组件。 ```html <template> <div> <e-charts :options="chartOptions" :auto-resize="true" ref="chart"></e-charts> </div> </template> ``` 通过以上步骤,你就可以在Vue3中使用echarts饼状图了。记得在引用组件的时候添加v-if判断来解决刷新不及时的问题。<span class="em">1</span> #### 引用[.reference_title] - *1* [vue3+echarts实现炫酷的百分比饼图,echarts组件封装](https://blog.csdn.net/xu20166424/article/details/128558713)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值