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>
相关推荐
军军君011 小时前
数字孪生监控大屏实战模板:商圈大数据监控
前端·javascript·vue.js·typescript·前端框架·echarts·three
smilejingwei1 天前
用 AI 编程生成 ECharts 图表并嵌入报表的实践
前端·人工智能·echarts·bi·报表工具·商业智能
吴声子夜歌1 天前
Vue3——表单元素绑定
前端·vue·es6
Highcharts.js1 天前
React 应用中的图表选择:Highcharts vs Apache ECharts 深度对比
前端·javascript·react.js·echarts·highcharts·可视化图表·企业级图表
yusirxiaer2 天前
为什么 markRaw 能修复 Vue 3 + ECharts 的 resize 报错
javascript·vue.js·echarts
Highcharts.js2 天前
抉择之巅:从2029年回望2026年——企业可视化“战略分水岭”?
前端·javascript·信息可视化·编辑器·echarts·highcharts
军军君012 天前
数字孪生监控大屏实战模板:空气污染监控
前端·javascript·vue.js·typescript·前端框架·echarts·数字孪生
DazedMen2 天前
前端自定义接口返回,想咋玩就咋玩
前端·vue·接口拦截
劉三岁3 天前
平板网页开发,px vs rem + 适配方案
vue·电脑
蓝黑20203 天前
Vue组件通信之emit
前端·javascript·vue