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>
相关推荐
山海云端有限公司2 天前
随机诗词API实战:Vue项目接入完整示例与5个常见坑
vue·实战·前端开发·跨域·api调用·随机诗词api
暗冰ཏོ2 天前
Spring Boot + Vue3 订单支付模块技术实现:支付单、回调验签、幂等处理与余额扣减
前端·spring boot·后端·vue·微信支付·支付宝支付
paopaokaka_luck2 天前
英语单词学习系统的设计与实现(基于艾宾浩斯遗忘曲线的智能复习机制、语音朗读、多题型测试与错题自动收录、Echarts图形化分析)
vue.js·spring boot·后端·echarts
万亿少女的梦1683 天前
基于Python的高考志愿填报辅助系统设计与实现
java·spring boot·python·mysql·vue
万亿少女的梦1683 天前
基于SpringBoot与Vue的历史博物馆展品展示与游客管理系统设计
spring boot·mysql·vue·系统设计·博物馆管理系统
衍生星球3 天前
SpringBoot3 + Vue3 + 微信小程序如何学习,以及学哪些技术,组件
sql·微信小程序·uni-app·vue·springboot
志尊宝4 天前
Vue3 环境搭建 + 第一个 HelloVue 项目(零基础入门)
vue.js·node.js·vue·css3
万亿少女的梦1684 天前
基于Spring Boot与Vue的繁星技术论坛系统设计与实现
java·spring boot·mysql·vue·系统设计
随心(cracker)5 天前
BeaverX Admin:一套真正能跑起来的开源管理后台
vue·.net·管理后台
万亿少女的梦1685 天前
基于SpringBoot的考研学习交流系统设计与开发
spring boot·mysql·vue·系统设计·论坛系统