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>
相关推荐
军军君013 小时前
数字孪生监控大屏实战模板:政务服务大数据
前端·javascript·vue.js·typescript·前端框架·echarts·less
吴声子夜歌5 小时前
Vue3——渲染函数
前端·vue.js·vue·es6
2501_913680005 小时前
Vue3项目快速接入AI助手的终极方案 - 让你的应用智能升级
前端·vue.js·人工智能·ai·vue·开源软件
吕永强7 小时前
基于SpringBoot+Vue校园报修系统的设计与实现(源码+论文+部署)
vue·毕业设计·springboot·毕业论文·报修系统·校园报修
阿部多瑞 ABU18 小时前
《智能学号抽取系统》V5.9.5 发布:精简代码,修复移动端文件读取核心 Bug
vue·html·bug
知识分享小能手2 天前
ECharts入门学习教程,从入门到精通,ECharts 数据可视化入门介绍(1)
学习·信息可视化·echarts
军军君012 天前
数字孪生监控大屏实战模板:商圈大数据监控
前端·javascript·vue.js·typescript·前端框架·echarts·three
smilejingwei3 天前
用 AI 编程生成 ECharts 图表并嵌入报表的实践
前端·人工智能·echarts·bi·报表工具·商业智能
吴声子夜歌3 天前
Vue3——表单元素绑定
前端·vue·es6
Highcharts.js3 天前
React 应用中的图表选择:Highcharts vs Apache ECharts 深度对比
前端·javascript·react.js·echarts·highcharts·可视化图表·企业级图表