vue3+heightchart实现3D饼图,echarts3D饼图,3D饼图引导线实现

 附上 heightcharts 官网地址 Highcharts 演示 | Highchartshttps://www.hcharts.cn/demo/highcharts

首先需要下载一下 heightcharts执行命令

npm install highcharts --save

 然后初始化:

<template>
  <div id="container" style="width: 600px; height: 400px"></div>
</template>

<script>
import { reactive, toRefs, ref, onMounted } from 'vue'
import Highcharts from 'highcharts' //必须引入
import Highcharts3D from 'highcharts/highcharts-3d' // 3D必须有引入
Highcharts3D(Highcharts)
export default {
  setup() {
    let pie = ref('')
    let state = reactive({})

    onMounted(() => {
      let colors = ['rgba(36, 154, 163, 0.6)', 'rgba(0, 255, 0,0.6)', 'rgba(255, 0, 255,0.6)']
      Highcharts.setOptions({
        colors: colors
      })
      Highcharts.chart(
        'container',
        {
          credits: {
            enabled: false, // 默认值,如果想去掉版权信息,设置为false即可
            text: 'www.hcharts.cn', // 显示的文字
            href: 'http://www.hcharts.cn', // 链接地址
            position: {
              // 位置设置
              align: 'left',
              x: 400,
              verticalAlign: 'bottom',
              y: -100
            },
            style: {
              // 样式设置
              cursor: 'pointer',
              color: 'red',
              fontSize: '30px'
            }
          },
          chart: {
            spacing: [40, 0, 40, 0],
            options3d: {
              enabled: true,
              alpha: 45
            }
          },
          title: {
            floating: true,
            text: '这里标题'
          },
          tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
          },
          plotOptions: {
            pie: {
              allowPointSelect: true,
              cursor: 'pointer',
              dataLabels: {
                enabled: true,
                format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                style: {
                  color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || '#fff'
                }
              },
              point: {
                // events: {
                //   mouseOver: function (e) {
                //     // 鼠标滑过时动态更新标题
                //     chart.setTitle({
                //       text: e.target.name + '\t' + e.target.y + ' %'
                //     })
                //   }
                // }
              },
              innerSize: 220,
              depth: 40
            }
          },
          series: [
            {
              type: 'pie',
              innerSize: '80%',
              name: '市场份额',
              data: [
                ['IE', 26],
                ['Safari', 18],
                ['Opera', 16],
                ['其他', 10]
              ]
            }
          ]
        },
        function (c) {
          // 图表初始化完毕后的会掉函数
          // 环形图圆心
          var centerY = c.series[0].center[1],
            titleHeight = parseInt(c.title.styles.fontSize)
          // 动态设置标题位置
          c.setTitle({
            y: centerY + titleHeight / 2
          })
        }
      )
    })
    return {
      ...toRefs(state),
      pie
    }
  }
}
</script>

<style lang="scss" scoped>
.pie {
  width: 100%;
  height: 100%;
}
</style>

如此你就得到了一个3D饼图 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
以下是使用Vue3和ECharts实现3D地的步骤: 1.安装EChartsECharts-GL插件 ```shell npm install echarts --save npm install echarts-gl --save ``` 2.在Vue3项目中引入EChartsECharts-GL ```javascript // 在main.js中引入 import * as echarts from 'echarts'; import 'echarts-gl'; ``` 3.创建一个Vue组件,并在其中引入ECharts ```vue <template> <div ref="chart" style="width: 100%; height: 100%;"></div> </template> <script> export default { name: 'EChartsMap', props: { // 地数据 mapData: { type: Object, required: true } }, mounted() { // 创建ECharts实例 const chart = echarts.init(this.$refs.chart); // 配置ECharts选项 const option = { // 设置地类型为3D地 globe: { baseTexture: '/img/earth.jpg', // 地球贴 heightTexture: '/img/bathymetry_bw_composite_4k.jpg', // 地形高度贴 displacementScale: 0.1, // 地形高度缩放比例 shading: 'realistic', // 地球材质 environment: '/img/starfield.jpg', // 星空贴 realisticMaterial: { roughness: 0.2 // 地球表面粗糙度 }, postEffect: { enable: true, SSAO: { enable: true, radius: 2 } }, light: { main: { intensity: 5, shadow: true }, ambient: { intensity: 0 } } }, // 设置地数据 series: [{ type: 'map3D', map: 'world', data: this.mapData, shading: 'lambert', label: { show: false }, itemStyle: { color: '#fff' }, emphasis: { label: { show: true } } }] }; // 使用刚指定的配置项和数据显示表。 chart.setOption(option); } }; </script> ``` 4.在父组件中使用EChartsMap组件,并传入地数据 ```vue <template> <div> <EChartsMap :mapData="mapData" /> </div> </template> <script> import EChartsMap from './EChartsMap.vue'; export default { name: 'App', components: { EChartsMap }, data() { return { mapData: [ { name: 'China', value: 100 }, { name: 'United States of America', value: 50 }, { name: 'Russia', value: 80 }, // ... ] }; } }; </script> ```
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈十一i

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值