Vue3 旭日图

效果图:

html 复制代码
<template>
    <div class="go-SunriseChart">
      <v-chart ref="vChartRef" :option="option" style="width: 100%; height: 400px;"></v-chart>
    </div>
  </template>
  
  <script setup lang="ts">
  import {
    ref,
    onMounted
  } from "vue";
  import VChart from "vue-echarts";
  import { use } from "echarts/core";
  import { CanvasRenderer } from "echarts/renderers";
  import { SunburstChart } from "echarts/charts";
  import {
    DatasetComponent,
    GridComponent,
    TooltipComponent,
    LegendComponent,
    TitleComponent,
  } from "echarts/components";
  
  use([
    DatasetComponent,
    GridComponent,
    TitleComponent,
    CanvasRenderer,
    SunburstChart,
    TooltipComponent,
    LegendComponent,
  ]);
  
  // 获取图表实例
  const vChartRef = ref();
  
  let colorList = [
    "#0674F1",
    "#029CD4",
    "#2BA471",
    "#F5BA18",
    "#E37318",
    "#E37318",
    "#E37318",
    "#E37318",
  ];
  let levelList = ["ff", "e5", "cc", "b2", "99", "7f", "66"];
  
  const setColor = (arr?: any, level?: any, mainColor?: any) => {
    let levelNum = level ? level + 1 : 1;
    for (let i = 0; i < arr.length; i++) {
      arr[i].itemStyle = {
        color: levelNum === 1 ? colorList[i] : mainColor + levelList[levelNum],
      };
      if (arr[i].children && arr[i].children.length > 0) {
        setColor(
          arr[i].children,
          levelNum,
          levelNum === 1 ? colorList[i] : mainColor
        );
      }
    }
  };
//   数据
  const dataJson = ref<any>([
    {
      name: "入户核实",
      value: 11,
      children: [
        {
          name: "救助",
          value: 7,
        },
      ],
    },
    {
      name: "未处理",
      value: 3,
    },
    {
      name: "电话问询",
      value: 3,
      children: [
        {
          name: "救助",
          value: 1,
        },
      ],
    },
  ]);
  
  // 设置颜色
  setColor(dataJson.value);
  
  const option = ref<any>({
    // title: {
    //   text: '旭日图示例',
    //   left: 'center'
    // },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      show: true,
      bottom: 10
    },
    series: {
      type: "sunburst",
      data: dataJson.value,
      radius: ["40%", "90%"],
      itemStyle: {
        borderRadius: 0,
        borderWidth: 0,
      },
      label: {
        show: true,
        rotate: 0,
        position: "inside",
        formatter: `{b}: {c}人`,
        fontSize: 10,
        fontFamily: "Arial",
        textShadowColor: "transparent",
        shadowColor: "transparent",
      },
      emphasis: {
        label: {
          color: "#fff",
          show: true,
          rotate: 0,
          position: "inside",
          fontSize: 10,
          fontFamily: "Arial",
        },
        focus: 'ancestor'
      },
      labelLine: {
        normal: {
          show: false,
        },
      },
    },
  });
  
  // 确保组件挂载后正确渲染
  onMounted(() => {
    if (vChartRef.value) {
      // 可以在这里执行额外的图表操作
    }
  });
  </script>
  
  <style scoped>
  .go-SunriseChart {
    background-color: #000;
    width: 100%;
    height: 400px;
  }
  </style>
相关推荐
by__csdn3 小时前
JavaScript性能优化:减少重绘和回流(Reflow和Repaint)
开发语言·前端·javascript·vue.js·性能优化·typescript·vue
毕设源码-钟学长3 小时前
【开题答辩全过程】以 高校健康申报系统为例,包含答辩的问题和答案
java·tomcat·echarts
凯小默3 小时前
【TypeScript+Vue3+Vite+Vue-router+Vuex+Mock 进行 WEB 前端项目实战】学习笔记共 89 篇(完结)
typescript·echarts·mock·vue3·vite·vuex·vue-router
是梦终空16 小时前
计算机毕业设计252—基于Java+Springboot+vue3+协同过滤推荐算法的农产品销售系统(源代码+数据库+2万字论文)
java·spring boot·vue·毕业设计·源代码·协同过滤算法·农产品销售系统
Beginner x_u21 小时前
从组件点击事件到业务统一入口:一次前端操作链的完整解耦实践
前端·javascript·vue·业务封装
毕设源码-钟学长1 天前
【开题答辩全过程】以 基于Echarts的电商用户数据可视化平台设计与实现- -为例,包含答辩的问题和答案
前端·信息可视化·echarts
苏打水com1 天前
第十篇:Day28-30 工程化优化与部署——从“能跑”到“好用”(对标职场“项目上线”需求)
前端·css·vue·html·js
武哥聊编程1 天前
【从0带做】基于Springboot3+Vue3的生态养殖管理系统
java·学习·vue·毕业设计·springboot
xiaoxue..1 天前
从 “手动搬砖“ 到 “自动施法“:界面开发的三次 “渡劫“ 升级记
前端·前端框架·vue