当前位置: 首页 > news >正文

Vue3 桑基图

效果图:

<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 { SankeyChart } from "echarts/charts"; import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent, } from "echarts/components"; import cloneDeep from "lodash/cloneDeep"; use([ DatasetComponent, CanvasRenderer, SankeyChart, GridComponent, TooltipComponent, LegendComponent, ]); const vChartRef = ref<typeof VChart>(); const chartData = ref<any>({ label: [ { name: "a", }, { name: "b", }, { name: "a1", }, { name: "a2", }, { name: "b1", }, { name: "b2", }, ], links: [ { source: "a", target: "a1", value: 5, }, { source: "a", target: "a2", value: 3, }, { source: "b", target: "b1", value: 8, }, { source: "a", target: "b1", value: 3, }, { source: "b1", target: "a1", value: 1, }, { source: "b1", target: "b2", value: 2, }, ], }); const seriesItem = ref<any>({ type: "sankey", layout: "none", data: <any>[], links: <any>[], animation: true, animationDuration: 1000, animationEasing: 'cubicOut', // 节点配置 nodeWidth: 20, nodeGap: 8, nodeAlign: 'justify', // 节点对齐方式: 'left', 'right', 'center', 'justify' // 边配置 lineStyle: { color: 'source', // 或 'target', 'gradient' opacity: 0.4, curveness: 0.5, // 边的曲率 width: 'emphasis' // 或具体数值 }, // 节点标签 label: { show: true, position: 'right', // 'left', 'right', 'top', 'bottom', 'inside' color: '#333', fontSize: 12, fontWeight: 'normal', overflow: 'truncate' // 文本溢出处理 }, // 节点标签高亮 labelLayout: { hideOverlap: true, // 隐藏重叠标签 moveOverlap: 'shiftY' // 移动重叠标签 }, // 高亮状态 emphasis: { focus: 'adjacency', // 高亮相邻节点和边 blurScope: 'coordinateSystem' // 淡化范围 }, // 选中状态 select: { disabled: false // 是否禁用选中 }, // 节点高亮样式 emphasisNode: { label: { show: true, color: '#000', fontSize: 14, fontWeight: 'bold' } }, // 边高亮样式 emphasisLineStyle: { opacity: 0.8, width: 2 }, // 渐变色配置 // color: [ // '#5470c6', // '#91cc75', // '#fac858', // '#ee6666', // '#73c0de', // '#3ba272', // '#fc8452', // '#9a60b4', // '#ea7ccc' // ], // 数据排序 orient: 'horizontal', // 'vertical' // 拖拽配置 draggable: true, // 是否可拖拽 // 节点层级配置 levels: [ { depth: 0, itemStyle: { color: '#fbb4ae' }, label: { color: '#000' } }, { depth: 1, itemStyle: { color: '#b3cde3' } }, { depth: 2, itemStyle: { color: '#ccebc5' } } ] }); const getSeries = () => { let series: any = []; const values = chartData.value; if (values.label === undefined || values.links === undefined) { return; } //系列模板 let item: any = cloneDeep(seriesItem.value); item.data = values.label; item.links = values.links; series = item; return series; }; const option = reactive({ // 标题配置 title: { show: true, text: '桑基图', left: 'center', textStyle: { fontSize: 16, fontWeight: 'bold' } }, // 提示框 tooltip: { show: true, trigger: 'item', triggerOn: 'mousemove', formatter: (params: any) => { if (params.dataType === 'node') { return `${params.name}<br/>总量: ${params.value || 0}`; } else if (params.dataType === 'edge') { return `${params.data.source} → ${params.data.target}<br/>流量: ${params.data.value}`; } return ''; } }, // 图例 legend: { show: true, type: 'scroll', // 可滚动 orient: 'horizontal', left: 'center', top: 'bottom' }, // 网格配置 grid: { show: false, left: '10%', right: '10%', top: '10%', bottom: '15%' }, series: getSeries(), }) </script>
http://www.cnnetsun.cn/news/158677.html

相关文章:

  • 28nm以下工艺PMIC设计雷区:LOD、WPE、HKMG如何悄悄毁掉你的LDO?
  • Abaqus水力压裂模拟:基于Cohesive单元与XFEM的方法研究
  • 44、COMSOL模拟二维裂隙流压裂水平井裂缝性油藏离散裂缝网络模型COMSOL数值模拟案例
  • 今天咱们来聊聊ReliefF算法,一个在分类数据特征选择中相当实用的工具。废话不多说,直接上代码,边看边聊
  • MATLAB R2018A环境下的液相色谱信号自动调优降噪算法——交叉验证作为参数调节器
  • 计算机Java毕设实战-基于springboot的足球训练营系统的设计与实现设计与实现基于SpringBoot的青训足球综合运营平台设计与实现 【完整源码+LW+部署说明+演示视频,全bao一条龙等】
  • 2025年软件测试技术发展趋势与从业者应对策略
  • 电驱动(电机+电控)开发验证方法与技巧的高清视频教程,深入讲解精细技术,掌握实用技巧
  • 每天24小时的电价(元/kWh)
  • C#编程下的自定义控件与OpenCVSharp结合应用:卡尺测距功能实现
  • NGBoost-shap方法回归任务,由斯坦福吴恩达团队提出,属于集成模型的一种2019年提出的
  • Langchain-Chatchat Kubernetes集群部署策略
  • Langchain-Chatchat日志监控与性能分析最佳实践
  • Langchain-Chatchat模型微调指南:适配垂直领域任务
  • 如何配置IPv6静态路由?解决企业网络难题
  • 【Linux网络基础】详解 TCP 面向连接 vs UDP 无连接
  • Langchain-Chatchat如何评估问答质量?指标体系构建
  • springboot在线教育系统(11528)
  • 测了多款AI自动生成PPT工具,真正能用的不到一半
  • springboot星之语明星周边产品销售网站的设计与实现(11529)
  • 毕设救星:Spring Boot + Neo4j 打造“医疗知识问答”——基于知识图谱的智能导诊平台
  • 华为网络设备基本配置命令
  • 志同道合交友网站毕业论文+PPT(附源代码+演示视频)
  • 【Java 25 LTS六大核心特性】
  • Langchain-Chatchat助力医疗文档智能检索与问答
  • Langchain-Chatchat如何实现文档相似度比对?查重与去重依据
  • java学习--String和StringBuffer互转
  • 如何用Langchain-Chatchat实现本地化AI智能问答?
  • Langchain-Chatchat如何处理多义词歧义?上下文感知消歧算法
  • Langchain-Chatchat如何实现文档访问统计?了解知识使用情况