news 2026/4/16 10:44:41

Vue3 桑基图

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
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>
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/12 6:34:30

Langchain-Chatchat在社保查询服务中的落地场景

Langchain-Chatchat在社保查询服务中的落地场景 在政务服务日益数字化的今天&#xff0c;一个看似简单的“失业保险怎么领”问题&#xff0c;背后却牵动着政策文件、地方细则、历史沿革和个性化条件的复杂交织。群众反复跑窗口、电话咨询排长队、网上信息碎片化——这些传统服务…

作者头像 李华
网站建设 2026/4/15 14:26:04

【I2C协议】

规格和从机地址传输1、I2C的信号2、数据的有效性&#xff08;I2C是电平触发采样&#xff09;SDA的可变化时机数据线&#xff08;SDA&#xff09;上的数据只能在时钟线&#xff08;SCL&#xff09;为低电平时进行改变。SDA的稳定性SCL为高电平期间&#xff0c;SDA必须保持稳定。…

作者头像 李华
网站建设 2026/4/11 5:49:05

会议论文A RAG Approach for Generating Competency Questions in Ontology Engineering

此文章发表在MTSR2024会议&#xff0c;主题和能力问题有关&#xff0c;另外结合了RAG。 作者信息 荷兰的机构&#xff0c;文章12页。 要点1 我在2024年想到所谓需求驱动&#xff0c;也是结合能力问题的。当时觉得能力问题像是上个世纪的产物&#xff0c;一种古老的验证手段…

作者头像 李华
网站建设 2026/4/16 8:00:46

钻井工程的老师傅们总爱念叨一句话——井筒周围的应力分布能决定钻井成败。今天咱们用COMSOL做个流固耦合的实战模拟,看看地层压力是怎么在井筒周围“搞事情“的

COMSOL模拟流固耦合井筒周围应力分布。 此案列介绍在井筒壁周围施加径向荷载(孔压和地应力&#xff09;&#xff0c;分析其径向应力、环向应力以及孔压变化&#xff0c;附有详细的建模说明书。打开COMSOL新建模型&#xff0c;先选"多物理场耦合"里的达西流-固体力学接…

作者头像 李华