highcharts 3D环形饼图

效果图
底座图片
1.下载安装highcharts

npm install highcharts --save

2.在页面引入

import highcharts from 'highcharts'

3.在main.js引入

import highcharts from 'highcharts'
import highcharts3d from 'highcharts/highcharts-3d'
highcharts3d(highcharts)

4.html部分代码

		<div class="echartsBox">
          <div class="chart-container">
            <div class="textColor">{{  this.arrValue[0] }}</div>
            <div id="echartsid1"
                 class="chartsid"></div>
            <!-- 底座背景 -->
            <div class="bg"></div>
          </div>
          <div class="chart-container">
            <div class="textColor textColor2">{{  this.arrValue[1] }}</div>
            <div id="echartsid2"
                 class="chartsid"></div>
            <!-- 底座背景 -->
            <div class="bg"></div>
          </div>
          <div class="chart-container">
            <div class="textColor textColor3">{{  this.arrValue[2] }}</div>
            <div id="echartsid3"
                 class="chartsid"></div>
            <!-- 底座背景 -->
            <div class="bg"></div>
          </div>
          <div class="chart-container">
            <div class="textColor textColor4">{{  this.arrValue[3] }}</div>
            <div id="echartsid4"
                 class="chartsid"></div>
            <!-- 底座背景 -->
            <div class="bg"></div>
          </div>
        </div>

5.css部分代码

.echartsBox {
  display: flex;
  width: 100%;
  justify-content: space-around;
}
.chart-container {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  .textColor {
    font-size: 16px;
    font-weight: bold;
    color: #0659e6;
  }
  .textColor2 {
    color: #5c98bc;
  }
  .textColor3 {
    color: #4fc05c;
  }
  .textColor4 {
    color: #44aba9;
  }
  .chartsid {
    height: 80px;
    width: 100px;
    margin-bottom: -20px;
  }
  .bg {
    position: absolute;
    bottom: -25px;
    // left: 50%;
    z-index: 0;
	width: 100%;
    height: 100%;
    background: no-repeat center;
    background-image: url('~@/assets/screenImage/chartbg.png');
    background-size: auto;
  }
}

6.js部分代码

  • 在data中定义
	  dataList: [],
      dataList1: [],
      dataList2: [],
      dataList3: [],
  • js方法

	initOption(a) { // 后端数据
      let a1 = parseFloat(a[0])
      this.dataList = [   // 数据格式
        {
          name: '大型企业',
          y: a1,     // 数据值
          h: 10,     // 饼图高度
          bfb: 0,
        },
        {
          name: 'all',
          y: 100,
          h: 5,
          bfb: 0,
        },
      ]
      let a2 = parseFloat(a[1])
      this.dataList1 = [
        {
          name: '中型企业',
          y: a2,
          h: 10,
          bfb: 0,
        },
        {
          name: 'all',
          y: 100,
          h: 5,
          bfb: 0,
        },
      ]
      let a3 = parseFloat(a[2])
      this.dataList2 = [
        {
          name: '小型企业',
          y: a3,
          h: 10,
          bfb: 0,
        },
        {
          name: 'all',
          y: 100,
          h: 5,
          bfb: 0,
        },
      ]
      let a4 = parseFloat(a[3])
      this.dataList3 = [
        {
          name: '微型企业',
          y: a4,
          h: 10,
          bfb: 0,
        },
        {
          name: 'all',
          y: 100,
          h: 5,
          bfb: 0,
        },
      ]
      // 修改3d饼图绘制过程

      var each = highcharts.each,
        round = Math.round,
        cos = Math.cos,
        sin = Math.sin,
        deg2rad = Math.deg2rad
      highcharts.wrap(
        highcharts.seriesTypes.pie.prototype,

        'translate',

        function (proceed) {
          proceed.apply(this, [].slice.call(arguments, 1))

          // Do not do this if the chart is not 3D

          if (!this.chart.is3d()) {
            return
          }

          var series = this,
            chart = series.chart,
            options = chart.options,
            seriesOptions = series.options,
            depth = seriesOptions.depth || 0,
            options3d = options.chart.options3d,
            alpha = options3d.alpha,
            beta = options3d.beta,
            z = seriesOptions.stacking
              ? (seriesOptions.stack || 0) * depth
              : series._i * depth

          z += depth / 2

          if (seriesOptions.grouping !== false) {
            z = 0
          }

          each(series.data, function (point) {
            var shapeArgs = point.shapeArgs,
              angle

            point.shapeType = 'arc3d'

            var ran = point.options.h

            shapeArgs.z = z

            shapeArgs.depth = depth * 0.75 + ran

            shapeArgs.alpha = alpha

            shapeArgs.beta = beta

            shapeArgs.center = series.center

            shapeArgs.ran = ran

            angle = (shapeArgs.end + shapeArgs.start) / 2

            point.slicedTranslation = {
              translateX: round(
                cos(angle) * seriesOptions.slicedOffset * cos(alpha * deg2rad)
              ),

              translateY: round(
                sin(angle) * seriesOptions.slicedOffset * cos(alpha * deg2rad)
              ),
            }
          })
        }
      )
      highcharts.chart('echartsid1', {
        tooltip: {
          enabled: false,  // 隐藏tooltip
          followPointer: false, // this is already the default, it's just to stress what's said in commit comments and make code "speak"
          followTouchMove: false, // this is already the default, it's just to stress what's said in commit comments and make code "speak"
        },
        chart: {
          animation: false,
          backgroundColor: 'none',
          type: 'pie', //饼图
          margin: [0, 0, 0, 0],
          options3d: {
            enabled: true, //使用3d功能
            alpha: 70, //延y轴向内的倾斜角度  
            beta: 0,
          },
          events: {
            load: function () {
              var each = highcharts.each,
                points = this.series[0].points

              each(points, function (p, i) {
                p.graphic.attr({
                  translateY: -p.shapeArgs.ran,
                })

                p.graphic.side1.attr({
                  translateY: -p.shapeArgs.ran,
                })

                p.graphic.side2.attr({
                  translateY: -p.shapeArgs.ran,
                })
              })
            },
          },
        },
        legend: {
          show: false,
          enabled: false, // 关闭图例
          align: 'right', //水平方向位置
          verticalAlign: 'top', //垂直方向位置
          layout: 'vertical',
          x: -20,
          y: 30,
          symbolWidth: 10,
          symbolHeight: 10,
          symbolRadius: '50%', // 修改成圆
          itemMarginBottom: 8,
          useHTML: false,
          //labelFormat: '{name}&nbsp;&nbsp;&nbsp;&nbsp;{y}',
          // labelFormatter: function () {
          //   return (
          //     '<div style="width: .3125rem;display: inline-block">' +
          //     this.name +
          //     ':&nbsp;&nbsp;</div><div style="color: #00d7da;display: inline-block">' +
          //     this.y +
          //     '</div>'
          //   )
          // },

          itemStyle: {
            color: '#f4f4f6',

            fontSize: 12,
          },
        },

        title: {
          // enabled: false,
          text: '',
        },
        subtitle: {
          text: '',
        },
        plotOptions: {
          pie: {
            allowPointSelect: false, // 禁用点击
            cursor: 'pointer',
            depth: 0,
            showInLegend: false,
            size: '55%', // 外圈直径大小
            innerSize: 30, // 内圈直径大小
            center: ['50%', '35%'],
            colors: ['#3a59f0', '#0349C1'],
            dataLabels: {
              useHTML: false,
              enabled: false, //是否显示饼图的线形tip
              distance: 5,
              borderColor: '#007acc',
              align: 'center',
              // verticalAlign: 'top',
              position: 'right',
              // format: '{point.bfb}%',
              // formatter: (point,b) => {
              //   console.log(point,'ponit-->>')
              //   console.log(b,'ponit-->>')
              // },
              // color: '#ffffff',
              // style: {
              //   textOutline: 'none',
              //   fontSize: 13,
              // },
            },
          },
          series: {
            states: {
              inactive: {
                opacity: 1,
              },
            },
          },
        },
        credits: {
          enabled: false, // 禁用版权信息
        },
        series: [
          {
            type: 'pie',
            name: '数量',
            data: this.dataList,
          },
        ],
      })
      highcharts.chart('echartsid2', {
        tooltip: {
          enabled: false,
          followPointer: false, // this is already the default, it's just to stress what's said in commit comments and make code "speak"
          followTouchMove: false, // this is already the default, it's just to stress what's said in commit comments and make code "speak"
        },
        chart: {
          animation: false,
          backgroundColor: 'none',
          type: 'pie', //饼图
          margin: [0, 0, 0, 0],
          options3d: {
            enabled: true, //使用3d功能
            alpha: 70, //延y轴向内的倾斜角度
            beta: 0,
          },
          events: {
            load: function () {
              var each = highcharts.each,
                points = this.series[0].points

              each(points, function (p, i) {
                p.graphic.attr({
                  translateY: -p.shapeArgs.ran,
                })

                p.graphic.side1.attr({
                  translateY: -p.shapeArgs.ran,
                })

                p.graphic.side2.attr({
                  translateY: -p.shapeArgs.ran,
                })
              })
            },
          },
        },
        legend: {
          show: false,
          enabled: false, // 关闭图例
          align: 'right', //水平方向位置
          verticalAlign: 'top', //垂直方向位置
          layout: 'vertical',
          x: -20,
          y: 30,
          symbolWidth: 10,
          symbolHeight: 10,
          symbolRadius: '50%', // 修改成圆
          itemMarginBottom: 8,
          useHTML: false,
          //labelFormat: '{name}&nbsp;&nbsp;&nbsp;&nbsp;{y}',
          // labelFormatter: function () {
          //   return (
          //     '<div style="width: .3125rem;display: inline-block">' +
          //     this.name +
          //     ':&nbsp;&nbsp;</div><div style="color: #00d7da;display: inline-block">' +
          //     this.y +
          //     '</div>'
          //   )
          // },

          itemStyle: {
            color: '#f4f4f6',

            fontSize: 12,
          },
        },

        title: {
          // enabled: false,
          text: '',
        },
        subtitle: {
          text: '',
        },
        plotOptions: {
          pie: {
            allowPointSelect: false, // 禁用点击
            cursor: 'pointer',
            depth: 0,
            showInLegend: false,
            size: '55%', // 外圈直径大小
            innerSize: 30, // 内圈直径大小
            center: ['50%', '35%'],
            colors: ['#5495cd', '#0349C1'],
            dataLabels: {
              useHTML: false,
              enabled: false, //是否显示饼图的线形tip
              distance: 5,
              borderColor: '#007acc',
              align: 'center',
              // verticalAlign: 'top',
              position: 'right',
              // format: '{point.bfb}%',
              // formatter: (point,b) => {
              //   console.log(point,'ponit-->>')
              //   console.log(b,'ponit-->>')
              // },
              // color: '#ffffff',
              // style: {
              //   textOutline: 'none',
              //   fontSize: 13,
              // },
            },
          },
          series: {
            states: {
              inactive: {
                opacity: 1,
              },
            },
          },
        },
        credits: {
          enabled: false, // 禁用版权信息
        },
        series: [
          {
            type: 'pie',
            name: '数量',
            data: this.dataList1,
          },
        ],
      })
      highcharts.chart('echartsid3', {
        tooltip: {
          enabled: false,
          followPointer: false, // this is already the default, it's just to stress what's said in commit comments and make code "speak"
          followTouchMove: false, // this is already the default, it's just to stress what's said in commit comments and make code "speak"
        },
        chart: {
          animation: false,
          backgroundColor: 'none',
          type: 'pie', //饼图
          margin: [0, 0, 0, 0],
          options3d: {
            enabled: true, //使用3d功能
            alpha: 70, //延y轴向内的倾斜角度
            beta: 0,
          },
          events: {
            load: function () {
              var each = highcharts.each,
                points = this.series[0].points

              each(points, function (p, i) {
                p.graphic.attr({
                  translateY: -p.shapeArgs.ran,
                })

                p.graphic.side1.attr({
                  translateY: -p.shapeArgs.ran,
                })

                p.graphic.side2.attr({
                  translateY: -p.shapeArgs.ran,
                })
              })
            },
          },
        },
        legend: {
          show: false,
          enabled: false, // 关闭图例
          align: 'right', //水平方向位置
          verticalAlign: 'top', //垂直方向位置
          layout: 'vertical',
          x: -20,
          y: 30,
          symbolWidth: 10,
          symbolHeight: 10,
          symbolRadius: '50%', // 修改成圆
          itemMarginBottom: 8,
          useHTML: false,
          //labelFormat: '{name}&nbsp;&nbsp;&nbsp;&nbsp;{y}',
          // labelFormatter: function () {
          //   return (
          //     '<div style="width: .3125rem;display: inline-block">' +
          //     this.name +
          //     ':&nbsp;&nbsp;</div><div style="color: #00d7da;display: inline-block">' +
          //     this.y +
          //     '</div>'
          //   )
          // },

          itemStyle: {
            color: '#f4f4f6',

            fontSize: 12,
          },
        },

        title: {
          // enabled: false,
          text: '',
        },
        subtitle: {
          text: '',
        },
        plotOptions: {
          pie: {
            allowPointSelect: false, // 禁用点击
            cursor: 'pointer',
            depth: 0,
            showInLegend: false,
            size: '55%', // 外圈直径大小
            innerSize: 30, // 内圈直径大小
            center: ['50%', '35%'],
            colors: ['#4caf5a', '#0349C1'],
            dataLabels: {
              useHTML: false,
              enabled: false, //是否显示饼图的线形tip
              distance: 5,
              borderColor: '#007acc',
              align: 'center',
              // verticalAlign: 'top',
              position: 'right',
              // format: '{point.bfb}%',
              // formatter: (point,b) => {
              //   console.log(point,'ponit-->>')
              //   console.log(b,'ponit-->>')
              // },
              // color: '#ffffff',
              // style: {
              //   textOutline: 'none',
              //   fontSize: 13,
              // },
            },
          },
          series: {
            states: {
              inactive: {
                opacity: 1,
              },
            },
          },
        },
        credits: {
          enabled: false, // 禁用版权信息
        },
        series: [
          {
            type: 'pie',
            name: '数量',
            data: this.dataList2,
          },
        ],
      })
      highcharts.chart('echartsid4', {
        tooltip: {
          enabled: false,
          followPointer: false, // this is already the default, it's just to stress what's said in commit comments and make code "speak"
          followTouchMove: false, // this is already the default, it's just to stress what's said in commit comments and make code "speak"
        },
        chart: {
          animation: false,
          backgroundColor: 'none',
          type: 'pie', //饼图
          margin: [0, 0, 0, 0],
          options3d: {
            enabled: true, //使用3d功能
            alpha: 70, //延y轴向内的倾斜角度
            beta: 0,
          },
          events: {
            load: function () {
              var each = highcharts.each,
                points = this.series[0].points

              each(points, function (p, i) {
                p.graphic.attr({
                  translateY: -p.shapeArgs.ran,
                })

                p.graphic.side1.attr({
                  translateY: -p.shapeArgs.ran,
                })

                p.graphic.side2.attr({
                  translateY: -p.shapeArgs.ran,
                })
              })
            },
          },
        },
        legend: {
          show: false,
          enabled: false, // 关闭图例
          align: 'right', //水平方向位置
          verticalAlign: 'top', //垂直方向位置
          layout: 'vertical',
          x: -20,
          y: 30,
          symbolWidth: 10,
          symbolHeight: 10,
          symbolRadius: '50%', // 修改成圆
          itemMarginBottom: 8,
          useHTML: false,
          //labelFormat: '{name}&nbsp;&nbsp;&nbsp;&nbsp;{y}',
          // labelFormatter: function () {
          //   return (
          //     '<div style="width: .3125rem;display: inline-block">' +
          //     this.name +
          //     ':&nbsp;&nbsp;</div><div style="color: #00d7da;display: inline-block">' +
          //     this.y +
          //     '</div>'
          //   )
          // },

          itemStyle: {
            color: '#f4f4f6',

            fontSize: 12,
          },
        },

        title: {
          // enabled: false,
          text: '',
        },
        subtitle: {
          text: '',
        },
        plotOptions: {
          pie: {
            allowPointSelect: false, // 禁用点击
            cursor: 'pointer',
            depth: 0,
            showInLegend: false,
            size: '55%', // 外圈直径大小
            innerSize: 30, // 内圈直径大小
            center: ['50%', '35%'],
            colors: ['#2FAAA7', '#0349C1'],
            dataLabels: {
              useHTML: false,
              enabled: false, //是否显示饼图的线形tip
              distance: 5,
              borderColor: '#007acc',
              align: 'center',
              // verticalAlign: 'top',
              position: 'right',
              // format: '{point.bfb}%',
              // formatter: (point,b) => {
              //   console.log(point,'ponit-->>')
              //   console.log(b,'ponit-->>')
              // },
              // color: '#ffffff',
              // style: {
              //   textOutline: 'none',
              //   fontSize: 13,
              // },
            },
          },
          series: {
            states: {
              inactive: {
                opacity: 1,
              },
            },
          },
        },
        credits: {
          enabled: false, // 禁用版权信息
        },
        series: [
          {
            type: 'pie',
            name: '数量',
            data: this.dataList3,
          },
        ],
      })
    },
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Vue中使用Highcharts绘制3D饼图,首先需要在你的项目中安装vue-highcharts库,并在main.js中引入HighchartsHighcharts-3D模块。可以按照以下步骤进行操作: 1. 使用npm在你的项目中安装vue-highcharts库。 2. 在main.js中引入HighchartsHighcharts-3D模块: import highcharts from 'highcharts' import highcharts3d from 'highcharts/highcharts-3d' highcharts3d(highcharts) 3. 在Vue组件中使用vue-highcharts组件,并设置你的3D饼图的配置。 4. 参考上述的Vue教程来绘制3D饼图。 通过以上步骤,你就可以在Vue中使用Highcharts库绘制3D饼图了。请确保你已经正确安装了依赖库并按照引用和引用提供的方法进行配置。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [【highCharts绘制3d饼图】有、无高低差的3d饼图](https://blog.csdn.net/phhzhhh/article/details/125807211)[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_2"}}] [.reference_item style="max-width: 50%"] - *3* [vue单页面中使用 highcharts 绘制3D饼图](https://blog.csdn.net/qq_46566911/article/details/121280786)[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_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值