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>
相关推荐
toooooop81 天前
UniApp Vue2 动态修改 SCSS 伪类颜色
vue
这是个栗子1 天前
微信小程序开发(九)- uni-app微信小程序商城
微信小程序·小程序·uni-app·vue·vuex
文阿花1 天前
Echarts实现3D饼状图
前端·javascript·echarts·饼状图
鹤鸣的日常2 天前
前端运行时动态环境变量方案
前端·react.js·docker·前端框架·vue·gitlab
文阿花2 天前
Echarts实现自动旋转柱状3D扇形图
前端·3d·echarts
文阿花2 天前
Echarts实现自定旋转3D饼状图
javascript·3d·echarts·饼状图
文阿花2 天前
Echarts实现柱状3D扇形图
android·3d·echarts
San813_LDD2 天前
[Vue/HTML]ECharts 使用指南:从入门到绘制各种常用图表
vue.js·html·echarts
来杯@Java3 天前
学生选课管理系统(基于springboot+vue前后端分离的项目)计算机毕业设计java
java·spring boot·spring·vue·毕业设计·maven·mybatis
医疗信息化王工3 天前
医院自律端系统——预警处置模块全栈实战(ASP.NET Core + Vue3 + Quartz 定时调度)
mysql·postgresql·vue·asp.net core·quartz