Vue3 矩形树图

效果图:

html 复制代码
<template>
  <v-chart ref="vChartRef" :option="option"></v-chart>
</template>

<script setup lang="ts">
import { ref, reactive } from "vue";
import VChart from "vue-echarts";
import { use } from "echarts/core";
import { CanvasRenderer } from "echarts/renderers";
import { TreemapChart } from "echarts/charts";
import { TooltipComponent, VisualMapComponent } from "echarts/components";
import cloneDeep from "lodash/cloneDeep";

use([CanvasRenderer, TreemapChart, TooltipComponent, VisualMapComponent]);

const vChartRef = ref<typeof VChart>();

const seriesItem = ref<any>({
  name: "treemap",
  type: "treemap",
  leafDepth: 1,
  roam: false,
  animationDuration: 1000,
  animationEasing: 'quinticInOut',
  breadcrumb: {
    show: true,
    height: 22,
    textStyle: {
      color: '#666',
      fontSize: 12
    }
  },
  nodeClick: 'zoomToNode',
  zoomToNodeRatio: 0.32 * 0.32,
//   levels: [ // 层级设置
//     {
//       itemStyle: {
//         borderColor: '#ddd',
//         borderWidth: 2,
//         gapWidth: 2
//       },
//       upperLabel: {
//         show: true,
//         height: 30,
//         textStyle: {
//           color: '#333',
//           fontSize: 14
//         }
//       }
//     },
//     {
//       itemStyle: {
//         borderColor: '#aaa',
//         gapWidth: 1,
//         borderColorSaturation: 0.1
//       }
//     }
//   ],
  upperLabel: {
    show: true,
    height: 30,
    textStyle: {
      color: '#fff',
      fontSize: 12
    }
  },
  label: {
    show: true,
    textStyle: {
      color: '#fff',
      fontSize: 14,
      fontWeight: 'bold'
    }
  },
  itemStyle: {
    borderColor: '#fff',
    // borderWidth: 2,
    // gapWidth: 2
  },
  data: <any>[],
});

const chartData = ref<any>([
  {
    name: "东涌镇",
    value: 20,
  },
  {
    name: "万顷沙镇",
    value: 20,
  },
  {
    name: "龙穴街道",
    value: 30,
  },
  {
    name: "珠江街道",
    value: 40,
  },
  {
    name: "横沥镇",
    value: 50,
  },
  {
    name: "大岗镇",
    value: 60,
  },
  {
    name: "黄阁镇",
    value: 70,
  },
  {
    name: "榄核镇",
    value: 80,
  },
]);
const getSeries = () => {
  let series: any = [];
  const values = chartData.value;
  //系列模板
  let item = cloneDeep(seriesItem.value);
  item.data = values;
  series.push(item);
  return series;
};
const option = reactive({
  tooltip: {
    trigger: 'item',
    formatter: (info: any) => {
      return `${info.name}<br/>值: ${info.value}`;
    }
  },
  visualMap: {
    type: 'continuous',
    min: 0,
    max: 100,
    inRange: {
    //   color: ['#FF6B35', '#F7931E', '#FFD200', '#AFD339', '#59BA47', '#00A896', '#028090', '#05668D']
    },
    calculable: true,
    show: false
  },
  series: getSeries(),
});
</script>
相关推荐
RuoyiOffice2 小时前
企业请假销假系统设计实战:一张表、一套流程、两段生命周期——BPM节点驱动的表单变形术
java·spring·uni-app·vue·产品运营·ruoyi·anti-design-vue
Mephisto1805026 小时前
Vue 3 变量声明和调用
vue
RuoyiOffice6 小时前
SpringBoot+Vue3+Uniapp实现PC+APP双端考勤打卡设计:GPS围栏/内网双模打卡、节假日方案、定时预生成——附数据结构和核心源码讲解
java·spring·小程序·uni-app·vue·产品运营·ruoyi
Irene19917 小时前
Vue 2、Vue 3 、Vuex 3、Vuex 4 和 Pinia 响应式丢失场景及解决方案
vue·pinia·vuex
Julyued1 天前
vue3开发echarts热力图
前端·echarts
Java陈序员1 天前
自建 Claude Code 镜像!一站式开源中转服务!
docker·node.js·vue·claude·claude code
呆头鸭L1 天前
Electron进程通信
前端·javascript·electron·前端框架·vue
木斯佳1 天前
前端八股文面经大全: 蓝色光标前端一面OC(2026-03-23)·面经深度解析
前端·面试·vue·校招·js·面经
旭久1 天前
react+echarts实现2d地图标记点与影响区域及可拖拽放大缩小等功能
react.js·echarts·swift
蜡台2 天前
SPA(Single Page Application) Web 应用(即单页应用)架构模式 更新
前端·架构·vue·react·spa·spa更新