当前位置: 首页> 财经> 产业 > 随州网站建设推荐_com域名为什么那么贵_三只松鼠的软文范例_网站开发建设步骤

随州网站建设推荐_com域名为什么那么贵_三只松鼠的软文范例_网站开发建设步骤

时间:2025/7/11 0:09:08来源:https://blog.csdn.net/PorkCanteen/article/details/144990898 浏览次数:1次
随州网站建设推荐_com域名为什么那么贵_三只松鼠的软文范例_网站开发建设步骤

背景

项目上需要对Echarts饼图进行功能定制,实现点击颜色块,下钻显示下一层级占比

说明

饼图实现点击下钻/面包屑返回的功能
在这里插入图片描述

实现

  • 数据结构
[{name: 'a',value: 1,children: [...]},...
]
  • 点击下钻
// 为图表绑定点击事件(需要在destroy前进行事件解绑)
this.myChart.on('click', (e) => {if (e.data?.children) {this.source = e.data.children // 将子级用于当前图表显示this.breadcrumbList.push(e.data.name) // 面包屑添加子级名称}
})
  • 面包屑返回
<!-- 面包屑-显示下钻层级及点击返回 数据结构: [xxx, xxx, ...] -->
<row class="breadcrumb" v-if="drillAble"><spanclass="clickable flex"v-for="(item, index) in breadcrumbList":key="index"@click="handleCrumbClick(index)"><OverflowTip style="max-width: 200px" :content="item">{{ item }}</OverflowTip><span class="px-5" v-if="index < breadcrumbList.length - 1"> / </span></span>
</row>
handleCrumbClick(index) { // index为点击面包屑的层级if (index === this.breadcrumbList.length - 1) return // 点击当前层级 不做任何操作this.breadcrumbList.splice(index + 1) // 删除下级面包屑if (index === 0) {this.source = this.originData // 根级别 直接赋值} else {const parentName = this.breadcrumbList[index]const parentData = this.findParentData(this.originData, parentName) // 递归查找this.source = parentData?.children || []}
},
findParentData(data, name) {for (const item of data) {if (item.name === name) {return item; // 找到对应的父级节点}if (item.children) {const result = this.findParentData(item.children, name);if (result) {return result; // 在子级中递归查找}}}return null; // 如果没有找到
},
关键字:随州网站建设推荐_com域名为什么那么贵_三只松鼠的软文范例_网站开发建设步骤

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: