手動實現legend 與 echarts圖交互 通過js事件實現圖標某項的高亮 顯示與隱藏

通過html實現legend的樣式 提供調用echarts的api實現與echarts圖表交互的效果

實現餅圖element實現類似于legend與echartstu表交互效果

效果圖

在這里插入圖片描述

配置代碼

<template><div style="height: 400px; width: 500px;background-color: #CCC;"><v-chart:option="options"autoresizestyle="width: 100%; height: 100%"ref="chart"/><div style="display: flex; margin-right: 20px"><divv-for="item in dataList":key="item.name"style="display: flex;align-items: center; margin-top: 10px; margin-right: 20px;cursor: pointer"@mouseenter="handleMouseenter(item)"@mouseleave="handleMouseleave(item)"@click="handleClick(item)"><i :style="{'background-color': item.isShow ? item.itemStyle.color: '#CCC'}" style="width: 10px;height:10px;border-radius: 50%;margin-right: 5px"></i><span style="margin-right:10px;">{{item.name}}</span><span>{{item.value}}</span></div></div></div>
</template><script>export default {name: 'AboutView',data() {return{dataList: [{ value: 1048, name: 'Search Engine',isShow: true,itemStyle: {color: '#006699'} },{ value: 735, name: 'Direct',isShow: true,itemStyle: {color: '#009966'}  },{ value: 580, name: 'Email',isShow: true,itemStyle: {color: '#FFCC00'}  },]}},computed: {options() {return {tooltip: {trigger: 'item'},legend:{show: false},series: [{name: 'Access From',type: 'pie',radius: ['45%', '50%'],center: ['50%', '38.5%'],avoidLabelOverlap: false,label: {show: false,position: 'center'},labelLine: {show: false},data: this.dataList}]}}},methods: {handleMouseenter(item){this.$refs.chart.dispatchAction({type: 'highlight',name: item.name,// seriesIndex: 1// dataIndex: 1// // 用 index 或 id 或 name 來指定系列。// // 可以使用數組指定多個系列。// seriesIndex?: number | number[],// seriesId?: string | string[],// seriesName?: string | string[],// // 數據項的 index,如果不指定也可以通過 name 屬性根據名稱指定數據項// dataIndex?: number | number[],// // 可選,數據項名稱,在有 dataIndex 的時候忽略// name?: string | string[],})},handleMouseleave(item){this.$refs.chart.dispatchAction({type: 'downplay',name: item.name,// seriesIndex: 1// dataIndex: 1// // 用 index 或 id 或 name 來指定系列。// // 可以使用數組指定多個系列。// seriesIndex?: number | number[],// seriesId?: string | string[],// seriesName?: string | string[],// // 數據項的 index,如果不指定也可以通過 name 屬性根據名稱指定數據項// dataIndex?: number | number[],// // 可選,數據項名稱,在有 dataIndex 的時候忽略// name?: string | string[],})},handleClick(item){item.isShow = !item.isShowthis.$refs.chart.dispatchAction({type: 'legendToggleSelect',name: item.name,// // 用 index 或 id 或 name 來指定系列。// // 可以使用數組指定多個系列。// seriesIndex?: number | number[],// seriesId?: string | string[],// seriesName?: string | string[],// // 數據項的 index,如果不指定也可以通過 name 屬性根據名稱指定數據項// dataIndex?: number | number[],// // 可選,數據項名稱,在有 dataIndex 的時候忽略// name?: string | string[],})}}}
</script><style lang="scss" scoped></style>

通過js實現柱形圖同一組數據時 隱藏某一個柱子

效果圖

在這里插入圖片描述

配置代碼

<template><div style="height: 400px; width: 500px;background-color: #CCC;"><v-chart:option="options"autoresizestyle="width: 100%; height: 100%"ref="chart"/><div style="display: flex; margin-right: 20px"><divv-for="item in dataList":key="item.name"style="display: flex;align-items: center; margin-top: 10px; margin-right: 20px;cursor: pointer"@click="handleClick(item)"@mouseenter="handleMouseenter(item)"@mouseleave="handleMouseleave(item)"><i :style="{'background-color': item.isShow ? item.itemStyle.color: '#CCC'}" style="width: 10px;height:10px;border-radius: 50%;margin-right: 5px"></i><span style="margin-right:10px;">{{item.name}}</span><span>{{item.value}}</span></div></div></div>
</template><script>export default {name: 'AboutView',data() {return{dataList: [{ value: 1048, name: 'Search Engine',isShow: true,itemStyle: {color: '#006699'} },{ value: 735, name: 'Direct',isShow: true,itemStyle: {color: '#009966'}  },{ value: 580, name: 'Email',isShow: true,itemStyle: {color: '#FFCC00'}  },]}},computed: {options() {return {tooltip: {trigger: 'item'},legend:{show: false},xAxis: {type: 'category',data: this.computedSeriesData.map(item => item.name)},yAxis: {type: 'value'},series: [{name: 'Access From',type: 'bar',radius: ['45%', '50%'],center: ['50%', '38.5%'],avoidLabelOverlap: false,label: {show: false,position: 'center'},labelLine: {show: false},data: this.computedSeriesData}]}},computedSeriesData() {return this.dataList.filter(item => item.isShow)}},methods: {handleClick(item){item.isShow = !item.isShow},handleMouseenter(item){this.$refs.chart.dispatchAction({type: 'highlight',name: item.name,// seriesIndex: 1// dataIndex: 1// // 用 index 或 id 或 name 來指定系列。// // 可以使用數組指定多個系列。// seriesIndex?: number | number[],// seriesId?: string | string[],// seriesName?: string | string[],// // 數據項的 index,如果不指定也可以通過 name 屬性根據名稱指定數據項// dataIndex?: number | number[],// // 可選,數據項名稱,在有 dataIndex 的時候忽略// name?: string | string[],})},handleMouseleave(item){this.$refs.chart.dispatchAction({type: 'downplay',name: item.name,// seriesIndex: 1// dataIndex: 1// // 用 index 或 id 或 name 來指定系列。// // 可以使用數組指定多個系列。// seriesIndex?: number | number[],// seriesId?: string | string[],// seriesName?: string | string[],// // 數據項的 index,如果不指定也可以通過 name 屬性根據名稱指定數據項// dataIndex?: number | number[],// // 可選,數據項名稱,在有 dataIndex 的時候忽略// name?: string | string[],})},}}
</script><style lang="scss" scoped></style>

通過js實現柱形圖一組數據的顯示隱藏 達到legend的效果

效果圖

在這里插入圖片描述
在這里插入圖片描述

配置代碼

<template><div style="height: 400px; width: 500px;background-color: #CCC;"><v-chart:option="options"autoresizestyle="width: 100%; height: 100%"ref="chart"/><div style="display: flex; margin-right: 20px"><divv-for="item in legendList":key="item.name"style="display: flex;align-items: center; margin-top: 10px; margin-right: 20px;cursor: pointer"@click="handleClick(item)"@mouseenter="handleMouseenter(item)"@mouseleave="handleMouseleave(item)"><i :style="{'background-color': item.isShow ? item.color: '#CCC'}" style="width: 10px;height:10px;border-radius: 50%;margin-right: 5px"></i><span style="margin-right:10px;">{{item.name}}</span><span>{{item.value}}</span></div></div></div>
</template><script>export default {name: 'AboutView',data() {return{legendList: [{ name: '測試1', isShow: true, color: '#00BFFF' },{ name: '測試2', isShow: true, color: '#FFD700'},],dataList1: [{ value: 1048, name: 'Search Engine' },{ value: 735, name: 'Direct'},{ value: 580, name: 'Email'},],dataList2: [{ value: 800, name: 'Search Engine' },{ value: 335, name: 'Direct'},{ value: 1580, name: 'Email'},]}},computed: {options() {return {tooltip: {trigger: 'item'},legend:{show: false},xAxis: {type: 'category',data: this.dataList1.map(item => item.name)},yAxis: {type: 'value'},series: [{name: '測試1',type: 'bar',radius: ['45%', '50%'],center: ['50%', '38.5%'],avoidLabelOverlap: false,label: {show: false,position: 'center'},labelLine: {show: false},itemStyle:{color: '#00BFFF'},data: this.dataList1},{name: '測試2',type: 'bar',radius: ['45%', '50%'],center: ['50%', '38.5%'],avoidLabelOverlap: false,label: {show: false,position: 'center'},labelLine: {show: false},itemStyle:{color: '#FFD700'},data: this.dataList2}]}},},methods: {handleClick(item){item.isShow = !item.isShowthis.$refs.chart.dispatchAction({type: 'legendToggleSelect',// 圖例名稱name: item.name,// // 下列參數自 v5.6.0 起開始支持// // 圖例組件ID// legendId: string,// // 圖例組件索引// legendIndex: number,// // 圖例組件名稱// legendName: string})},handleMouseenter(item){this.$refs.chart.dispatchAction({type: 'highlight',seriesName: item.name// seriesIndex: 1// dataIndex: 1// // 用 index 或 id 或 name 來指定系列。// // 可以使用數組指定多個系列。// seriesIndex?: number | number[],// seriesId?: string | string[],// seriesName?: string | string[],// // 數據項的 index,如果不指定也可以通過 name 屬性根據名稱指定數據項// dataIndex?: number | number[],// // 可選,數據項名稱,在有 dataIndex 的時候忽略// name?: string | string[],})},handleMouseleave(item){this.$refs.chart.dispatchAction({type: 'downplay',seriesName: item.name// seriesIndex: 1// dataIndex: 1// // 用 index 或 id 或 name 來指定系列。// // 可以使用數組指定多個系列。// seriesIndex?: number | number[],// seriesId?: string | string[],// seriesName?: string | string[],// // 數據項的 index,如果不指定也可以通過 name 屬性根據名稱指定數據項// dataIndex?: number | number[],// // 可選,數據項名稱,在有 dataIndex 的時候忽略// name?: string | string[],})},}}
</script><style lang="scss" scoped></style>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/77021.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/77021.shtml
英文地址,請注明出處:http://en.pswp.cn/web/77021.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Spring Boot 配置源詳解(完整版)

Spring Boot 配置源詳解&#xff08;完整版&#xff09; 一、配置源加載順序與優先級 配置源類型優先級順序&#xff08;從高到低&#xff09;對應配置類/接口是否可覆蓋典型文件/來源命令行參數&#xff08;--keyvalue&#xff09;1&#xff08;最高&#xff09;SimpleComman…

【無人機】無人機遙控器設置與校準,飛行模式的選擇,無線電控制 (RC) 設置

目錄 1、遙控器校準 1.1、校準步驟 2、飛行模式選擇&#xff0c;遙控器通道映射 2.1、配置步驟 1、遙控器校準 在校準無線電系統之前&#xff0c;必須連接/綁定接收器和發射器。綁定發射器和接收器對的過程是特定于硬件的&#xff08;有關說明&#xff0c;請參閱 RC 手冊&…

Redis 有序集合 ZSet 深度解析教程

Redis-ZSet 引言一、 ZSet 核心概念與特性1.1 什么是 ZSet&#xff1f;1.2 ZSet 與 Set、List 的本質區別 二、 ZSet 典型應用場景2.1 排行榜 (Leaderboards)2.2 帶權重的任務隊列 / 延遲隊列2.3 時間軸 (Timeline)2.4 范圍查找 三、 ZSet 底層實現3.1 ziplist (壓縮列表)3.2 s…

【SpringBoot】HttpServletRequest獲取使用及失效問題(包含@Async異步執行方案)

目錄 1. 在 Controller 方法中作為參數注入 2.使用 RequestContextHolder &#xff08;1&#xff09;失效問題 &#xff08;2&#xff09;解決方案一&#xff1a; &#xff08;3&#xff09;解決方案二&#xff1a; 3、使用AutoWrite自動注入HttpServletRequest 跨線程調…

mfc學習(一)

mfc為微軟創建的一個類qt框架的客戶端程序&#xff0c;只不過因為微軟目前有自己 的親身兒子C#&#xff08;.net&#xff09;,所以到2010沒有進行維護。然后一些的工業企業還在繼續進行維護相關的內容。我目前就接手一個現在這樣的項目&#xff0c;其實本質與qt的思路是差不多的…

HarmonyOS:一多能力介紹:一次開發,多端部署

概述 如果一個應用需要在多個設備上提供同樣的內容&#xff0c;則需要適配不同的屏幕尺寸和硬件&#xff0c;開發成本較高。HarmonyOS 系統面向多終端提供了“一次開發&#xff0c;多端部署”&#xff08;后文中簡稱為“一多”&#xff09;的能力&#xff0c;可以基于一種設計…

秒出PPT推出更強版本,AI PPT工具進入新紀元!

在現代職場中&#xff0c;PPT是我們溝通和展示信息的重要工具。無論是做產品演示&#xff0c;還是準備工作匯報&#xff0c;一份精美的PPT能大大提升演示效果。然而&#xff0c;傳統的PPT制作往往需要消耗大量時間&#xff0c;尤其是在排版、設計和內容調整上。如今&#xff0c…

Godot開發2D冒險游戲——第二節:主角光環整起來!

變量的作用域 全局變量&#xff0c;局部變量&#xff0c;導出變量&#xff08;可以在檢查器當中快速查看&#xff09; 為玩家添加移動動畫 現在游戲的玩家還只是在滑行&#xff0c;我們需要再添加玩家每個方向上的移動效果 刪除原先的Item節點&#xff0c;創建一個動畫精靈…

顛覆傳統NAS體驗:耘想WinNAS讓遠程存儲如同本地般便捷

在當今數據爆炸的時代&#xff0c;網絡附加存儲(NAS)已成為許多企業和個人用戶的必備設備。然而&#xff0c;傳統硬件NAS解決方案存在諸多限制&#xff0c;如高額成本、復雜設置和有限的遠程訪問能力。耘想WinNAS以其創新的軟件解決方案&#xff0c;徹底改變了這一局面&#xf…

新市場環境下新能源汽車電流傳感技術發展前瞻

新能源革命重構產業格局 在全球碳中和戰略驅動下&#xff0c;新能源汽車產業正經歷結構性變革。國際清潔交通委員會&#xff08;ICCT&#xff09;最新報告顯示&#xff0c;2023年全球新能源汽車滲透率突破18%&#xff0c;中國市場以42%的市占率持續領跑。這種產業變革正沿著&q…

STM32之DHT11溫濕度傳感器---附代碼

DHT11簡介 DHT11的供電電壓為 3&#xff0d;5.5V。 傳感器上電后&#xff0c;要等待 1s 以越過不穩定狀態在此期間無需發送任何指令。 電源引腳&#xff08;VDD&#xff0c;GND&#xff09;之間可增加一個100nF 的電容&#xff0c;用以去耦濾波。 DATA 用于微處理器與DHT11之間…

#define STEUER_A_H {PWM_A_ON}

目錄 一、括號的區別 二、實例講解 三、注意事項 四、總結 五、補充 一、括號的區別 大括號 {}: 在 C/C 中&#xff0c;大括號一般用于表示一個代碼塊或結構體、集合等。例如&#xff1a; 用于定義函數體、控制結構&#xff08;如 if、for&#xff09;的代碼塊。用于初始化…

Redis 緩存—處理高并發問題

Redis的布隆過濾器、單線程架構、雙寫一致性、比較穿透、擊穿及雪崩、緩存更新方案及分布式鎖。 1 布隆過濾器 是一種高效的概率型數據結構&#xff0c;用于判斷元素是否存在。主要用于防止緩存穿透&#xff0c;通過攔截不存在的數據查詢&#xff0c;避免擊穿數據庫。 原理&…

【玩轉全棧】—— 無敵前端究極動態組件庫--Inspira UI

目錄 Inspira UI 介紹 配置環境 使用示例 效果&#xff1a; Inspira UI 學習視頻&#xff1a; 華麗優雅 | Inspira UI快速上手_嗶哩嗶哩_bilibili 官網&#xff1a;https://inspira-ui.com/ Inspira UI 介紹 Inspira UI 是一個設計精美、功能豐富的用戶界面庫&#xff0c;專為…

【OpenCV圖像處理實戰】從基礎操作到工業級應用

目錄 前言技術背景與價值當前技術痛點解決方案概述目標讀者說明 一、技術原理剖析核心概念圖解核心作用講解關鍵技術模塊說明技術選型對比 二、實戰演示環境配置要求核心代碼實現&#xff08;6個案例&#xff09;案例1&#xff1a;圖像基本操作案例2&#xff1a;邊緣檢測案例3&…

fastjson使用parseObject轉換成JSONObject出現將字符特殊字符解析解決

現象&#xff1a;將字符串的${TARGET_VALUE}轉換成NULL字符串了問題代碼&#xff1a; import com.alibaba.fastjson.JSON;JSONObject config JSON.parseObject(o.toString()); 解決方法&#xff1a; 1.更換fastjson版本 import com.alibaba.fastjson2.JSON;或者使用其他JS…

Docker Compose 和 Kubernetes(k8s)區別

前言&#xff1a;Docker Compose 和 Kubernetes&#xff08;k8s&#xff09;是容器化技術中兩個常用的工具&#xff0c;但它們的定位、功能和適用場景有顯著區別。以下是兩者的核心對比&#xff1a; ??1. 定位與目標?? ??特性?? ??Docker Compose?? ??Kubernet…

【21天學習打卡挑戰賽】如何學習WEB安全:逼自己在短時間掌握WEB安全核心內容

&#x1f36c; 博主介紹 &#x1f468;?&#x1f393; 博主介紹&#xff1a;大家好&#xff0c;我是 _PowerShell &#xff0c;很高興認識大家~ ?主攻領域&#xff1a;【滲透領域】【數據通信】 【通訊安全】 【web安全】【面試分析】 &#x1f389;點贊?評論?收藏 養成習…

Oracle數據庫巡檢腳本

1.查詢實例信息 SELECT INST_ID, INSTANCE_NAME, TO_CHAR(STARTUP_TIME, YYYY-MM-DD HH24:MI:SS) AS STARTUP_TIME FROM GV$INSTANCE ORDER BY INST_ID; 2.查看是否歸檔 archive log list 3.查看數據庫參數 SELECT NAME , TYPE , VALUE FROM V$PARAMETER ORDER BY NAME; 4.…

Windows 安裝 JDK

下載 Java8 的下載直接訪問&#xff1a;https://www.oracle.com/java/technologies/downloads/#java8-windows https://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html 接受協議后點擊下載&#xff0c;再輸入賬號信息就可以下載了。 如果…