带【科技感】的Echarts 图表


Echarts脚本在线地址 https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js


引入Echarts 脚本后粘贴代码

vue2 代码:

html 复制代码
<template>
  <div>
    <div ref="col-2-row-2" class="col-2-row-2"></div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      config: {
        list: [
          {name: "垃圾治理", id: "scene_type_2", value: 11},
          {name: "生活垃圾", id: "random_clap_type_3", value: 5},
          {name: "水域治理", id: "scene_type_5", value: 1},
          {name: "生活污水", id: "random_clap_type_2", value: 4},
          {name: "文明乡风", id: "random_clap_type_6", value: 10},
          {name: "农业废弃物", id: "random_clap_type_4", value: 2},
          {name: "农村厕所", id: "random_clap_type_1", value: 6},
          {name: "其他问题", id: "random_clap_type_7", value: 0},
          {name: "基础设施", id: "scene_type_3", value: 6},
          {name: "村容村貌", id: "scene_type_1", value: 19},
          {name: "蓝天守卫", id: "scene_type_4", value: 2},
        ]
      }
    }
  },
  methods: {
    initEcharts(dom, config, fn) {
      let _self = this, angle = 0, myChart
      if (this.$echarts.init) {
        myChart = this.$echarts.init(dom, null);
      } else {
        myChart = this.$echarts(dom, null);
      }
      setInterval(() => {
        angle = angle + 3
        let option = fn(_self, config, angle)
        myChart.setOption(option, true);
        // eslint-disable-next-line no-undef
        // tools.loopShowTooltip(myChart, option, {loopSeries: true});
      }, 120);
    },
    col2row2(vm, config = {}, angle = 0){
      let data = [];//角度,用来做简单的动画效果的
      let { list = [] } = config
      let _self = this;
      let img = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMYAAADGCAYAAACJm/9dAAABS2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4KPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxMzggNzkuMTU5ODI0L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FEfI6WqF5KO37H8OB69DCtBtQjCvTM76ADnxcjZ5pfLJ1CXr2x1OBzaYkqkUYIUuBMcAxRIsSQe3gK4E/oTmQ0dmbVrGMRs/sT+jciXj/bQVwLHrmS7M3LT2qTRghT6ORkcODdEhfNAeyFB0schmwY+bWlT9D0LN5DT2rSejZhTyNnu0hwILMrcuAahVGyGJUe3wdHWnbEntvX7SP+F3gMbTUZAC1ywAkgMfQGqZb0TMKaUHP8OvomS7O1rxsqWtdUlOLVoejGdnzgD0S3v8IreGZi4I0fJydabmwHWoKTUR9tKRBitXo0MefkVI4zDxpam5MfL3WhBFSj/Z/nI/W7DQkXNOCdpE9jbbhVsSMbTcYARwFHI2aQ4X+748jQTQDWzKzLmMKCaNv4qvVzxbg2eBve/SLeTowjmg3WQP6NT02yL+Lmg/Lgr9VRGGAypU+SAijg7/DgF0LXLsZiWA2Cp68PgP7ypZarTEKMQzVIOPRr+rWJgivRkPA5cxVaIi1EJ+i2vAJVEOU7WrXtHCN0T3WovU+96DO6OEoksk4FNqn0n9F2tC+iGZUWy4CNuZqUZliYRRmI5pND2fUd0JDwKPRMGVLgfvKiRa0EegF1PxbDnyQq0UVwv8BNYmwIpIWBvwAAAAASUVORK5CYII='
      let color=['#FF801C', '#F5FF46', '#00FE65', '#00FEFF', '#ffa800', '#ff5b00', '#ff3000']
      let seriesOption = [
          {
              name: '',
              type: 'pie',
              clockWise: false,
              radius: ['33%', '38%'],
              y: '-25%',
              hoverAnimation: false,
              label: {
                  show: true,
                  position: 'outside',
                  color: '#ddd',
                  normal: {
                    show: true,
                    textStyle: {
                      fontSize: 12,
                      color: '#bbd0e8'
                    }
                  },
                  
              },
              itemStyle: {
                  normal: {
                      labelLine: {
                          length: 20,
                          length2: 40,
                          show: true,
                          color: '#00ffff',
                      },
                        // 数据 百分比
                      label: {
                        formatter: function (params) {
                            let percent = 0;
                            let total = 0;
                            for (let i = 0; i < list.length; i++) {
                                total += list[i].value;
                            }
                            percent = ((params.value / total) * 100).toFixed(0);
                            if (params.name !== '') {
                                return params.name + ':' + percent + '%';
                            } else {
                                return '';
                            }
                        },
                      }
                  },
              },
              data: data,
          },
          // 外线
          {
              name: 'ring5',
              type: 'custom',
              coordinateSystem: 'none',
              renderItem: function (params, api) {
                  return {
                      type: 'arc',
                      shape: {
                          cx: api.getWidth() / 2,
                          cy: api.getHeight() / 2.65,
                          r: Math.min(api.getWidth(), api.getHeight()) / 3.3,
                          startAngle: ((0 + angle) * Math.PI) / 180,
                          endAngle: ((90 + angle) * Math.PI) / 180,
                      },
                      style: {
                          stroke: '#00FEFF',
                          fill: 'transparent',
                          lineWidth: 1.5,
                      },
                      silent: true,
                  };
              },
              data: [0],
          },
          // 外点
          {
              name: 'ring5', //紫点
              type: 'custom',
              coordinateSystem: 'none',
              renderItem: function (params, api) {
                  let x0 = api.getWidth() / 2;
                  let y0 = api.getHeight() / 2.68;
                  let r = Math.min(api.getWidth(), api.getHeight()) / 3.3;
                  let point = _self.getCirlPoint(x0, y0, r, 90 + angle);
                  return {
                      type: 'circle',
                      shape: {
                          cx: point.x,
                          cy: point.y,
                          r: 4,
                      },
                      style: {
                          stroke: '#00FEFF', //绿
                          fill: '#00FEFF',
                      },
                      silent: true,
                  };
              },
              data: [0],
          },

          // 外线
          {
              name: 'ring5',
              type: 'custom',
              coordinateSystem: 'none',
              renderItem: function (params, api) {
                  return {
                      type: 'arc',
                      shape: {
                          cx: api.getWidth() / 2,
                          cy: api.getHeight() / 2.68,
                          r: Math.min(api.getWidth(), api.getHeight()) / 3.3,
                          startAngle: ((180 + angle) * Math.PI) / 180,
                          endAngle: ((270 + angle) * Math.PI) / 180,
                      },
                      style: {
                          stroke: '#00FEFF',
                          fill: 'transparent',
                          lineWidth: 1.5,
                      },
                      silent: true,
                  };
              },
              data: [0],
          },
          // 蓝色 -- 外点
          {
              name: 'ring5', 
              type: 'custom',
              coordinateSystem: 'none',
              renderItem: function (params, api) {
                  let x0 = api.getWidth() / 2;
                  let y0 = api.getHeight() / 2.68;
                  let r = Math.min(api.getWidth(), api.getHeight()) / 3.3;
                  let point = _self.getCirlPoint(x0, y0, r, 180 + angle);
                  return {
                      type: 'circle',
                      shape: {
                          cx: point.x,
                          cy: point.y,
                          r: 4,
                      },
                      style: {
                          stroke: '#00FEFF', //绿
                          fill: '#00FEFF',
                      },
                      silent: true,
                  };
              },
              data: [0],
          },
          {
              name: 'ring5',
              type: 'custom',
              coordinateSystem: 'none',
              renderItem: function (params, api) {
                  return {
                      type: 'arc',
                      shape: {
                          cx: api.getWidth() / 2,
                          cy: api.getHeight() / 2.68,
                          r: Math.min(api.getWidth(), api.getHeight()) / 3.8,
                          startAngle: ((270 + -angle) * Math.PI) / 180,
                          endAngle: ((40 + -angle) * Math.PI) / 180,
                      },
                      style: {
                          stroke: '#00FEFF',
                          fill: 'transparent',
                          lineWidth: 1.5,
                      },
                      silent: true,
                  };
              },
              data: [0],
          },
          // 橘色
          {
              name: 'ring5',
              type: 'custom',
              coordinateSystem: 'none',
              renderItem: function (params, api) {
                  return {
                      type: 'arc',
                      shape: {
                          cx: api.getWidth() / 2,
                          cy: api.getHeight() / 2.68,
                          r: Math.min(api.getWidth(), api.getHeight()) / 3.8,
                          startAngle: ((90 + -angle) * Math.PI) / 180,
                          endAngle: ((220 + -angle) * Math.PI) / 180,
                      },
                      style: {
                          stroke: '#00FEFF',
                          fill: 'transparent',
                          lineWidth: 1.5,
                      },
                      silent: true,
                  };
              },
              data: [0],
          },
          {
              name: 'ring5',
              type: 'custom',
              coordinateSystem: 'none',
              renderItem: function (params, api) {
                  let x0 = api.getWidth() / 2;
                  let y0 = api.getHeight() / 2.68;
                  let r = Math.min(api.getWidth(), api.getHeight()) / 3.8;
                  let point = _self.getCirlPoint(x0, y0, r, 90 + -angle);
                  return {
                      type: 'circle',
                      shape: {
                          cx: point.x,
                          cy: point.y,
                          r: 4,
                      },
                      style: {
                          stroke: '#00FEFF', //粉
                          fill: '#00FEFF',
                      },
                      silent: true,
                  };
              },
              data: [0],
          },
          {
              name: 'ring5', //绿点
              type: 'custom',
              coordinateSystem: 'none',
              renderItem: function (params, api) {
                  let x0 = api.getWidth() / 2;
                  let y0 = api.getHeight() / 2.68;
                  let r = Math.min(api.getWidth(), api.getHeight()) / 3.8;
                  let point = _self.getCirlPoint(x0, y0, r, 270 + -angle);
                  return {
                      type: 'circle',
                      shape: {
                          cx: point.x,
                          cy: point.y,
                          r: 4,
                      },
                      style: {
                          stroke: '#00FEFF', //绿
                          fill: '#00FEFF',
                      },
                      silent: true,
                  };
              },
              data: [0],
          },
      ];
      for (let i = 0; i < list.length; i++) {
          data.push(
              {
                  value: list[i].value,
                  name: list[i].name,
                  itemStyle: {
                      normal: {
                          borderWidth: 5,
                          shadowBlur: 20,
                          borderColor: color[i],
                          shadowColor: color[i],
                      },
                  },
              },
              {
                  value: 2,
                  name: '',
                  itemStyle: {
                    label: {
                        show: false,
                    },
                    normal: {
                        labelLine: {
                          show: false,
                        },
                        color: 'rgba(0, 0, 0, 0)',
                        borderColor: 'rgba(0, 0, 0, 0)',
                        borderWidth: 0,
                    },
                  },
              }
          )
        }
    return {
          color,
          title: {
              text: '问题类型',
              textAlign: 'center',
              left: '49%',
              top: '34%',
              textStyle: {
                  fontWeight: 'normal',
                  fontSize: 14,
                  color: '#bbd0e8',
                  textAlign: 'center',
              },
          },
          // 内环
          graphic: {
              elements: [
                  {
                      type: 'image',
                      z: 3,
                      style: {
                          image: img,
                          width: 80,
                          height: 80,
                      },
                      left: 'center',
                      top: '25%',
                      position: [100, 100],
                  },
              ],
          },
          tooltip: {
              show: false,
          },
          legend: {
              icon: 'circle',
              orient: 'horizontal',
              y: '76%',
              data: list.map(i => i.name),
              align: 'left',
              textStyle: {
                  fontSize: 12,
                  color: '#bbd0e8',
              },
              itemGap: 5,
          },
          toolbox: {
              show: false,
          },
          series: seriesOption,
      };
    },
     //获取圆上面某点的坐标(x0,y0表示坐标,r半径,angle角度)
    getCirlPoint(x0, y0, r, angle) {
      let x1 = x0 + r * Math.cos(angle * Math.PI / 180)
      let y1 = y0 + r * Math.sin(angle * Math.PI / 180)
      return {
          x: x1,
          y: y1
      }
    }
  },
  mounted() {
    let _self = this;
    _self.$nextTick(() => {
      _self.initEcharts(_self.$refs['col-2-row-2'], _self.config, _self.col2row2)
    })
  }
}
</script>
<style lang="scss" scoped>
.col-2-row-2 {
  width: 400px;
  height: 300px;
  background-color: rgb(4, 36, 63);
}
</style>

因为Vue2 停止维护了嘛,所以我们要与时俱进。

Vue3 + Ts 版本:

需要注意:
this.dom.getContext is not a function
这个报错是指图表的实例对象只能通过document 获取,不可以用ref<'ElFormInstance>()
也就是27行和30行

"echarts"指 UMD 全局,但当前文件是模块。请考虑改为添加导入
这句说的是echarts应该通过全局引入的方式,可以通过npm安装echarts 解决,也可以在适当的位置全局引入echarts 脚本

html 复制代码
<template>
  <div class="p-2">
    <div ref="col2Row2" class="col-2-row-2"></div>
  </div>
</template>

<script setup name="echarts" lang="ts">
import { getCurrentInstance, ref } from 'vue';

// 数据列表
const config = reactive({
  list: [
    {name: "垃圾治理", id: "scene_type_2", value: 11},
    {name: "生活垃圾", id: "random_clap_type_3", value: 5},
    {name: "水域治理", id: "scene_type_5", value: 1},
    {name: "生活污水", id: "random_clap_type_2", value: 4},
    {name: "文明乡风", id: "random_clap_type_6", value: 10},
    {name: "农业废弃物", id: "random_clap_type_4", value: 2},
    {name: "农村厕所", id: "random_clap_type_1", value: 6},
    {name: "其他问题", id: "random_clap_type_7", value: 0},
    {name: "基础设施", id: "scene_type_3", value: 6},
    {name: "村容村貌", id: "scene_type_1", value: 19},
    {name: "蓝天守卫", id: "scene_type_4", value: 2},
  ]
})
// 图表ref
const col2Row2 = ref<ElFormInstance>();

onMounted(() => {
  initEcharts(document.querySelector('.col-2-row-2'), config, row2Config)
})

// 初始化
const initEcharts = (dom: any, config: Object, fn: Function) => {
  let _self = this, angle = 0;
  let myChart = echarts.init(dom, undefined);
  setInterval(() => {
    angle = angle + 3
    let option = fn(_self, config, angle)
    myChart.setOption(option, true);
    // eslint-disable-next-line no-undef
    // tools.loopShowTooltip(myChart, option, {loopSeries: true});
  }, 120);
}

// 配置
const row2Config = (vm:any, config = {list: []}, angle = 0) => {
  let data:any = [];//角度,用来做简单的动画效果的
  let { list = [{value: '', name: ''}] } = config
  let _self = this;
  let img = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMYAAADGCAYAAACJm/9dAAABS2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4KPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxMzggNzkuMTU5ODI0LCAyMDE2LzA5LzE0LTAxOjA5OjAxICAgICAgICAiPgogPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIi8+CiA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgo8P3hwYWNrZXQgZW5kPSJyIj8+IEmuOgAAE/9JREFUeJztnXmQVeWZxn/dIA2UgsriGmNNrEQNTqSio0IEFXeFkqi4kpngEhXjqMm4MIldkrE1bnGIMmPcUkOiIi6gJIragLKI0Songo5ZJlHGFTADaoRuhZ4/nnPmnO4+l+7bfc85d3l+VV18373n3Ptyvve53/5+da1L6jDdYjgwBhgNHALMBn6Sq0VdcxlwGvACsAx4HliTq0VlRlNzY+LrfTO2o5LoDxwOHAmMA/4WiP+KzM3DqCJpAA4K/i4F2oBXgWbgWWAxsDEv48oZC6M9Q4EJwInAMcDAfM0pOXXA14K/y4FPgQXAfOBxYF1+ppUXFgYMBiYCp6PaoU+B694HFqEmyVJgVSbW9Y6bgCeBb6Am4GHALrH3B6L/+0RgM6pFHgQeAzZk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IpIWBvwAAAAASUVORK5CYII='
  let color=['#FF801C', '#F5FF46', '#00FE65', '#00FEFF', '#ffa800', '#ff5b00', '#ff3000']
  let seriesOption = [
    {
      name: '',
      type: 'pie',
      clockWise: false,
      radius: ['33%', '38%'],
      y: '-25%',
      hoverAnimation: false,
      label: {
        show: true,
        position: 'outside',
        color: '#ddd',
        normal: {
          show: true,
          textStyle: {
            fontSize: 12,
            color: '#bbd0e8'
          }
        },
      },
      itemStyle: {
        normal: {
          labelLine: {
            length: 20,
            length2: 40,
            show: true,
            color: '#00ffff',
          },
          // 数据 百分比
          label: {
            formatter: function (params:any) {
              let percent:number = 0;
              let total:number = 0;
              for (let i = 0; i < list.length; i++) {
                total += +(list[i].value);
              }
              percent = +((params.value / total) * 100).toFixed(0);
              if (params.name !== '') {
                return params.name + ':' + percent + '%';
              } else {
                return '';
              }
            },
          }
        },
      },
      data: data,
    },
    // 外线
    {
      name: 'ring5',
      type: 'custom',
      coordinateSystem: 'none',
      renderItem: function (params:any, api:any) {
        return {
          type: 'arc',
          shape: {
            cx: api.getWidth() / 2,
            cy: api.getHeight() / 2.65,
            r: Math.min(api.getWidth(), api.getHeight()) / 3.3,
            startAngle: ((0 + angle) * Math.PI) / 180,
            endAngle: ((90 + angle) * Math.PI) / 180,
          },
          style: {
            stroke: '#00FEFF',
            fill: 'transparent',
            lineWidth: 1.5,
          },
          silent: true,
        };
      },
      data: [0],
    },
    // 外点
    {
      name: 'ring5', //紫点
      type: 'custom',
      coordinateSystem: 'none',
      renderItem: function (params:any, api:any) {
        let x0 = api.getWidth() / 2;
        let y0 = api.getHeight() / 2.68;
        let r = Math.min(api.getWidth(), api.getHeight()) / 3.3;
        let point = getCirlPoint(x0, y0, r, 90 + angle);
        return {
          type: 'circle',
          shape: {
            cx: point.x,
            cy: point.y,
            r: 4,
          },
          style: {
            stroke: '#00FEFF', //绿
            fill: '#00FEFF',
          },
          silent: true,
        };
      },
      data: [0],
    },
    // 外线
    {
      name: 'ring5',
      type: 'custom',
      coordinateSystem: 'none',
      renderItem: function (params:any, api:any) {
        return {
          type: 'arc',
          shape: {
            cx: api.getWidth() / 2,
            cy: api.getHeight() / 2.68,
            r: Math.min(api.getWidth(), api.getHeight()) / 3.3,
            startAngle: ((180 + angle) * Math.PI) / 180,
            endAngle: ((270 + angle) * Math.PI) / 180,
          },
          style: {
            stroke: '#00FEFF',
            fill: 'transparent',
            lineWidth: 1.5,
          },
          silent: true,
        };
      },
      data: [0],
    },
    // 蓝色 -- 外点
    {
      name: 'ring5', 
      type: 'custom',
      coordinateSystem: 'none',
      renderItem: function (params:any, api:any) {
        let x0 = api.getWidth() / 2;
        let y0 = api.getHeight() / 2.68;
          let r = Math.min(api.getWidth(), api.getHeight()) / 3.3;
          let point = getCirlPoint(x0, y0, r, 180 + angle);
          return {
            type: 'circle',
            shape: {
              cx: point.x,
              cy: point.y,
              r: 4,
            },
            style: {
              stroke: '#00FEFF', //绿
              fill: '#00FEFF',
            },
            silent: true,
          };
        },
      data: [0],
    },
    {
      name: 'ring5',
      type: 'custom',
      coordinateSystem: 'none',
      renderItem: function (params:any, api:any) {
        return {
          type: 'arc',
            shape: {
              cx: api.getWidth() / 2,
              cy: api.getHeight() / 2.68,
              r: Math.min(api.getWidth(), api.getHeight()) / 3.8,
              startAngle: ((270 + -angle) * Math.PI) / 180,
              endAngle: ((40 + -angle) * Math.PI) / 180,
            },
            style: {
              stroke: '#00FEFF',
              fill: 'transparent',
              lineWidth: 1.5,
            },
            silent: true,
          };
        },
      data: [0],
    },
    // 橘色
    {
      name: 'ring5',
      type: 'custom',
      coordinateSystem: 'none',
      renderItem: function (params:any, api:any) {
        return {
          type: 'arc',
          shape: {
            cx: api.getWidth() / 2,
            cy: api.getHeight() / 2.68,
            r: Math.min(api.getWidth(), api.getHeight()) / 3.8,
            startAngle: ((90 + -angle) * Math.PI) / 180,
            endAngle: ((220 + -angle) * Math.PI) / 180,
          },
          style: {
            stroke: '#00FEFF',
            fill: 'transparent',
            lineWidth: 1.5,
          },
          silent: true,
        };
      },
      data: [0],
    },
    {
      name: 'ring5',
      type: 'custom',
      coordinateSystem: 'none',
      renderItem: function (params:any, api:any) {
        let x0 = api.getWidth() / 2;
        let y0 = api.getHeight() / 2.68;
        let r = Math.min(api.getWidth(), api.getHeight()) / 3.8;
        let point = getCirlPoint(x0, y0, r, 90 + -angle);
        return {
          type: 'circle',
          shape: {
            cx: point.x,
            cy: point.y,
            r: 4,
          },
          style: {
            stroke: '#00FEFF', //粉
            fill: '#00FEFF',
          },
          silent: true,
        };
      },
      data: [0],
    },
    {
      name: 'ring5', //绿点
      type: 'custom',
      coordinateSystem: 'none',
      renderItem: function (params:any, api:any) {
        let x0 = api.getWidth() / 2;
        let y0 = api.getHeight() / 2.68;
        let r = Math.min(api.getWidth(), api.getHeight()) / 3.8;
        let point = getCirlPoint(x0, y0, r, 270 + -angle);
        return {
          type: 'circle',
          shape: {
            cx: point.x,
            cy: point.y,
            r: 4,
          },
          style: {
            stroke: '#00FEFF', //绿
            fill: '#00FEFF',
          },
          silent: true,
        };
      },
      data: [0],
    },
  ];
  for (let i = 0; i < list.length; i++) {
    data.push(
      {
        value: list[i].value,
        name: list[i].name,
        itemStyle: {
          normal: {
            borderWidth: 5,
            shadowBlur: 20,
            borderColor: color[i],
            shadowColor: color[i],
          },
        },
      },
      {
        value: 2,
        name: '',
        itemStyle: {
          label: {
            show: false,
          },
          normal: {
            labelLine: {
              show: false,
            },
            color: 'rgba(0, 0, 0, 0)',
            borderColor: 'rgba(0, 0, 0, 0)',
            borderWidth: 0,
          },
        },
      }
    )
  }
  return {
    color,
    title: {
      text: '问题类型',
      textAlign: 'center',
      left: '49%',
      top: '34%',
      textStyle: {
        fontWeight: 'normal',
        fontSize: 14,
        color: '#bbd0e8',
        textAlign: 'center',
      },
    },
    // 内环
    graphic: {
      elements: [
        {
          type: 'image',
          z: 3,
          style: {
            image: img,
            width: 80,
            height: 80,
          },
          left: 'center',
          top: '25%',
          position: [100, 100],
        },
      ],
    },
    tooltip: {
      show: false,
    },
    legend: {
      icon: 'circle',
      orient: 'horizontal',
      y: '76%',
      data: list.map(i => i.name),
      align: 'left',
      textStyle: {
        fontSize: 12,
        color: '#bbd0e8',
      },
      itemGap: 5,
    },
    toolbox: {
      show: false,
    },
    series: seriesOption,
  };
}

//获取圆上面某点的坐标(x0,y0表示坐标,r半径,angle角度)
const getCirlPoint = (x0:number, y0:number, r:number, angle:number) => {
  let x1 = x0 + r * Math.cos(angle * Math.PI / 180)
  let y1 = y0 + r * Math.sin(angle * Math.PI / 180)
  return {
    x: x1,
    y: y1
  }
}

</script>
<style lang="scss" scoped>
.col-2-row-2 {
  width: 400px;
  height: 300px;
  background-color: rgb(4, 36, 63);
}
</style>

到底了!原创不易,转载请注明出处。

前端的学习不是一蹴而就,不积跬步无以至千里,不积小流无以成江海。持续不断的努力才能让你我有所收获

推荐阅读:

Vue自定义轮播
Vue动态换肤
css圣诞树 立体模型
vue Tips 轻提示
vue系列自定义加载页
CSS手绘图形

相关推荐
前端小小王1 小时前
pnpm、Yarn 和 npm 的区别?
前端·npm·node.js
supermapsupport1 小时前
使用npm包的工程如何引入mapboxgl-enhance/maplibre-gl-enhance扩展包
前端·webpack·npm·supermap·mapboxgl
牛奔1 小时前
windows nvm 切换node版本后,npm找不到
前端·windows·npm·node.js
鱼大大博客1 小时前
Edge SCDN酷盾安全重塑高效安全内容分发新生态
前端·安全·edge
鸭梨山大。1 小时前
NPM组件包 vant部分版本内嵌挖矿代码
前端·安全·npm·node.js·vue
蟾宫曲6 小时前
在 Vue3 项目中实现计时器组件的使用(Vite+Vue3+Node+npm+Element-plus,附测试代码)
前端·npm·vue3·vite·element-plus·计时器
秋雨凉人心6 小时前
简单发布一个npm包
前端·javascript·webpack·npm·node.js
liuxin334455666 小时前
学籍管理系统:实现教育管理现代化
java·开发语言·前端·数据库·安全
qq13267029406 小时前
运行Zr.Admin项目(前端)
前端·vue2·zradmin前端·zradmin vue·运行zradmin·vue2版本zradmin
魏时烟7 小时前
css文字折行以及双端对齐实现方式
前端·css