js处理echarts tooltip定时轮播

devtools/2024/9/30 0:32:45/

echarts_tooltip_0">echarts tooltip定时轮播

javascript">/*** echarts tooltip轮播* @param chart ECharts实例* @param chartOption echarts的配置信息* @param options object 选项* {*  interval    轮播时间间隔,单位毫秒,默认为3000*              true表示循环所有series的tooltip,false则显示指定seriesIndex的tooltip*  seriesIndex 默认为0,指定某个系列(option中的series索引)循环显示tooltip,*              当loopSeries为true时,从seriesIndex系列开始执行。* }* @returns {{clearLoop: clearLoop}|undefined}*/export function loopShowTooltip(myChart, option, num, time) {var defaultData = {// 设置默认值time: 3000,num: 14,}if (!time) {time = defaultData.time}if (!num) {num = defaultData.num}var count = 0var timeTicket = 0// 清除定时器function clearLoop() {if (timeTicket) {clearInterval(timeTicket)timeTicket = 0}myChart.off('mousemove', stopAutoShow)myChart.getZr().off('mousemove', zRenderMouseMove)// myChart.getZr().off('globalout', zRenderGlobalOut);}// 关闭轮播function stopAutoShow() {if (timeTicket) {clearInterval(timeTicket)timeTicket = 0}}function zRenderMouseMove(param) {if (param.event) {// 阻止canvas上的鼠标移动事件冒泡// param.event.cancelBubble = true;}stopAutoShow()}timeTicket && clearInterval(timeTicket)timeTicket = setInterval(function () {myChart.dispatchAction({type: 'downplay',seriesIndex: 0, // serieIndex的索引值   可以触发多个})myChart.dispatchAction({type: 'highlight',seriesIndex: 0,dataIndex: count,})myChart.dispatchAction({type: 'showTip',seriesIndex: 0,dataIndex: count,})count++if (count >= num) {count = 0}}, time)myChart.on('mouseover', function (params) {clearInterval(timeTicket)myChart.dispatchAction({type: 'downplay',seriesIndex: 0,})myChart.dispatchAction({type: 'highlight',seriesIndex: 0,dataIndex: params.dataIndex,})myChart.dispatchAction({type: 'showTip',seriesIndex: 0,dataIndex: params.dataIndex,})})myChart.on('mouseout', function () {timeTicket && clearInterval(timeTicket)timeTicket = setInterval(function () {myChart.dispatchAction({type: 'downplay',seriesIndex: 0, // serieIndex的索引值   可以触发多个})myChart.dispatchAction({type: 'highlight',seriesIndex: 0,dataIndex: count,})myChart.dispatchAction({type: 'showTip',seriesIndex: 0,dataIndex: count,})count++if (count >= 14) {count = 0}}, 3000)})return {clearLoop: clearLoop,}
}

使用

javascript"><template><!-- 洪水预演——中间(洪水演进渲染)——水深echarts下面的进度条和echarts --><div class="DepthChart-container"><div class="chart"><EchartsChunk ref="echartRef" :options="options"></EchartsChunk></div><div class="chart2"><EchartsChunk ref="waterChartRef" :options="waterOptions"></EchartsChunk></div></div>
</template><script>
import dayjs from 'dayjs'
import { cloneDeep } from 'lodash'
import { processDataAndSetYAxis } from '@/utils/chartDefault.js'
import { loopShowTooltip } from '@/utils/tooltip-auto-show-vue'
import { fourOptions, waterOptions } from './echarts.config'
export default {name: 'DepthChart',data() {return {timesList: [], // 时间序列options: null,waterOptions: null,tootipTimer: null}},computed: {},watch: {},mounted() {this.getTmList()},beforeDestroy() {if (this.tootipTimer) {clearInterval(this.tootipTimer)this.tootipTimer = null}},methods: {getTmList() {// 模拟30条数据const timesList = []for (let i = 0; i < 28; i++) {const obj = {tm: `2024-04-${i + 1} ${i + 1}:32:00`,jl: (Math.random() * 100).toFixed(2),drp: (Math.random() * 100).toFixed(2),inq: (Math.random() * 100).toFixed(2),otq: (Math.random() * 100).toFixed(2),wl: (Math.random() * 100).toFixed(2),kr: (Math.random() * 100).toFixed(2)}timesList.push(obj)}this.timesList = timesListthis.setChartOptions()this.setWaterOptions()},setChartOptions() {const { timesList } = thislet option = cloneDeep(fourOptions)let { xAxis, series } = optionif (!xAxis) returnif (!timesList.length) {this.options = { ...option }this.$refs.chartRef.setOption(this.options) // 更新echartsreturn}const tms = timesList.map((item) => dayjs(item.tm).format('MM-DD HH:mm'))xAxis[0].data = tmsxAxis[1].data = tmsconst keys = ['drp', 'inq', 'otq', 'wl', 'kr']series.forEach((item, index) => {item.data = timesList.map((item) => item[keys[index]])})const categorizedData = {降雨量: [],水位: [],流量: [],库容: []}series.forEach((item) => {const dataType = item.name.includes('流量')? '流量': item.name.includes('水位')? '水位': item.name.includes('库容')? '库容': '降雨量'categorizedData[dataType].push(...item.data.filter((value) => value))})const updatedOption = processDataAndSetYAxis(categorizedData, option)this.options = { ...updatedOption }const ref = this.$refs.echartRefref.setOption(this.options)this.tootipTimer && this.tootipTimer.clearLoop() // this.tootipTimer 在data里定义this.tootipTimer = 0this.tootipTimer = loopShowTooltip(ref.chart, this.options, 0, 1000)},setWaterOptions() {const { timesList } = thislet option = cloneDeep(waterOptions)let { xAxis, series } = optionif (!xAxis) returnif (!timesList.length) {this.waterOptions = { ...option }this.$refs.waterChartRef.setOption(this.waterOptions) // 更新echartsreturn}xAxis[0].data = timesList.map((item) => item.jl)series[0].data = timesList.map((item) => item.wl)this.waterOptions = { ...option }const ref = this.$refs.waterChartRefref.setOption(this.waterOptions)}}
}
</script><style lang='scss' scoped>
.DepthChart-container {.chart {width: 100%;height: 260px;}.chart2 {width: 100%;height: 130px;}
}
</style>

http://www.ppmy.cn/devtools/104944.html

相关文章

MySQL——事务与存储过程(一)事务管理(1)事务的概念

事务处理机制在程序开发过程中有着非常重要的作用&#xff0c;它可以使整个系统更加安全&#xff0c;保证在同一个事务中的操作具有同步性。 现实生活中&#xff0c;人们经常会进行转账操作&#xff0c;转账可以分为两部分来完成&#xff0c;转人和转出&#xff0c;只有这两个部…

Mybatis链路分析:JDK动态代理和责任链模式的应用

背景 此前写过关于代理模式的文章&#xff0c;参考&#xff1a;代理模式 动态代理功能&#xff1a;生成一个Proxy代理类&#xff0c;Proxy代理类实现了业务接口&#xff0c;而通过调用Proxy代理类实现的业务接口&#xff0c;实际上会触发代理类的invoke增强处理方法。 责任链功…

BOOTSTRAP VUE快速使用

步骤 1&#xff1a;安装 Bootstrap npm install bootstrap步骤 2&#xff1a;导入 Bootstrap import bootstrap使用组件 <buttoon type button classbtn btn-primary>

OpenCV 模板匹配教程

OpenCV 模板匹配教程 模板匹配是一种计算机视觉技术&#xff0c;用于在更大的图像&#xff08;源图像&#xff09;中查找较小的子图像&#xff08;模板图像&#xff09;。OpenCV 提供了多种模板匹配的方法&#xff0c;允许我们检测源图像中与模板最相似的位置。在本教程中&…

【3.6】贪心算法-解救生艇问题

一、题目 第 i 个人的体重为 people[i]&#xff0c;每艘船可以承载的最大重量为 limit。 每艘船最多可同时载两人&#xff0c;但条件是这些人的重量之和最多为 limit 。 返回载到每一个人所需的最小船数。(保证每个人都能被船载)。 二、解题思路 题目要求每艘船最多能载两人&…

单窗口IP代理设置指南:轻松搞定

在现代互联网生活中&#xff0c;IP代理已经成为了许多人日常上网的必备工具。单窗口IP代理是一种非常实用的代理方式&#xff0c;它允许你在同一个浏览器中为不同的窗口设置不同的IP地址&#xff0c;从而更好地保护隐私和实现多任务处理。今天&#xff0c;我们就来详细讲解一下…

AI引领,驱动未来:零售企业的新质生产力革命

在这个快节奏的零售世界里&#xff0c;每一天都充满了变数。但你是否想象过&#xff0c;当AI&#xff08;人工智能&#xff09;、驱动技术、商品计划软件以及新质生产力携手并进时&#xff0c;零售企业将如何焕发新生&#xff0c;轻松应对挑战&#xff0c;引领行业潮流&#xf…

数字芯片中I/O单元及电源domain布局中SIPI的考虑

芯片设计的物理实施过程通常也简称为布局布线&#xff08;P&R&#xff0c;Place-and-Route&#xff09;&#xff0c;布局一般被分为布局规划&#xff08;Floorplan&#xff09;和标准单元摆放&#xff08;Place&#xff09;两个过程。而其中的布局规划是芯片后端物理实现过…