【echarts】24、highchart+vue2 - 3D饼图

前言

基于highchart5.x和vue2实现
记录以便日后查阅

实现效果

在这里插入图片描述

代码实现

注意:安装依赖 yarn add hightcharts@5 -S

<template>
  <div class="chart-wrap">
    <div id="chart20" class="chart" />
  </div>
</template>

<script>
import Highcharts from 'highcharts/highstock'
import HighchartsMore from 'highcharts/highcharts-more'
import HighchartsDrilldown from 'highcharts/modules/drilldown'
import Highcharts3D from 'highcharts/highcharts-3d'
import Highmaps from 'highcharts/modules/map'
HighchartsMore(Highcharts)
HighchartsDrilldown(Highcharts)
Highcharts3D(Highcharts)
Highmaps(Highcharts)

export default {
  name: 'Index',
  data () {
    return {
      chart: null,
      data: [
        { name: '规上企业', value: 26},
        { name: '规下/小微企业', value: 150 }
      ]
    }
  },
  mounted() {
    this.createChartHandler()
  },
  methods: {
    // 创建图表
    createChartHandler () {
      const options = this.getChartOption(this.data)
      this.chart && this.chart.destroy()
      this.chart = new Highcharts.Chart('chart20', options)
    },
    // 获取图表配置项
    getChartOption (pieData) {
      const data = [
        {
          name: '规上企业',
          y: 13,
          color: '#00D7E9',
          sliced: true,
          selected: true
        },
        {
          name: '规下/小微企业',
          y: 8,
          color: '#1FB5FF'
        }
      ]
      data.forEach(item => {
        const temp = pieData.filter(elm => elm.name === item.name)
        item.y = temp[0].value
      })
      return {
        chart: {
          type: 'pie',
          backgroundColor: 'transparent',
          options3d: {
            enabled: true,
            alpha: 65,
            beta: 0
          }
        },
        title: {
          text: null
        },
        credits: {
          enabled: false
        },
        tooltip: {
          pointFormat: '<b>{point.y}</b>'
        },
        plotOptions: {
          pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            depth: 20,
            size: 160,
            distance: 1,
            zIndex: 1
          }
        },
        series: [{
          type: 'pie',
          name: '企业占比',
          data: data,
          dataLabels: {
            style: {
              'color': '#ffffff',
              'fontSize': '14px',
              'fontWeight': 'normal',
              'textOutline': 'none'
            },
            useHTML: true
          }
        }]
      }
    }
  }
}
</script>

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值