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

记录:echarts实现tooltip的某个数据常显和恢复

在这里插入图片描述

<template><div class="com-wapper"><div class="func-btns"><el-button type="primary" plain @click="showPoint('2023')">固定显示2023年数据</el-button><el-button type="success" plain @click="clearFixedTooltip">恢复</el-button></div><div ref="chartRef" class="chart-content"></div></div>
</template><script>
import * as echarts from "echarts";
export default {name: "com-page",components: {},props: {},data() {return {myData: {xData: ["2021", "2022", "2023", "2024", "2025"],dataList: [{name: "概率论",value: [61, 58, 72, 76, 83],},{name: "高等数学",value: [78, 62, 86, 83, 80],},{name: "离散数学",value: [91, 78, 66, 79, 92],},],},myChart: null,option: null,isShow: false,};},mounted() {this.drawingChart();window.addEventListener("resize", this.resize);},methods: {/*** 画图*/drawingChart() {this.myChart = echarts.init(this.$refs.chartRef);this.option = {grid: {containLabel: true,},legend: {data: this.myData.dataList.map((item) => {return {name: item.name,};}),},tooltip: {show: true,trigger: "axis",alwaysShowContent: false,},xAxis: [{type: "category",data: this.myData.xData,boundaryGap: true,},],yAxis: [{splitNumber: 5,min: 0,max: 100,},],series: this.myData.dataList.map((item) => {return {type: "line",data: item.value,name: item.name,smooth: true,showSymbol: true,};}),};this.myChart.setOption(this.option);},/*** 重置图表*/resize() {this.myChart && this.myChart.resize();},/*** 显示固定点的tooltip*/showPoint(point) {let xAxisData = this.myData.xData; // 横轴数据const index = xAxisData.findIndex((item) => item === point);if (index !== -1) {// 显示当前数据tooltipthis.myChart.dispatchAction({type: "showTip",seriesIndex: 0,dataIndex: index, // 要显示的数据点索引值});// 修改配置,保持tooltip一直显示this.myChart.setOption({tooltip: {alwaysShowContent: true,},});// 临时禁用鼠标事件this.myChart.getZr().off("globalout");this.myChart.getZr().off("click");this.myChart.getZr().off("mousemove");// 标记一下this.isShow = true;}},/*** 恢复tooltip的正常使用*/clearFixedTooltip() {if (this.isShow) {this.isShow = false;// 取消常显配置this.myChart.setOption({tooltip: {alwaysShowContent: false,},});// 恢复默认交互,重新绑定mousemove和globaloutconst zr = this.myChart.getZr();const that = this;zr.on("mousemove", function (e) {that.myChart._api.dispatchAction({type: "showTip",x: e.offsetX,y: e.offsetY,});});zr.on("globalout", function () {that.myChart._api.dispatchAction({type: "hideTip",});});// 隐藏当前tooltipthis.myChart.dispatchAction({type: "hideTip",});}},},beforeDestroy() {window.removeEventListener("resize", this.resize);this.myChart && this.myChart.dispose();},
};
</script><style lang='scss' scoped>
.com-wapper {height: 100%;.func-btns {text-align: center;}.chart-content {width: 100%;height: 70%;padding-top: 40px;margin-top: 30px;background: rgba(237, 237, 237, 0.2);}
}
</style>
http://www.lryc.cn/news/2378832.html

相关文章:

  • 八股文--JVM(1)
  • 从RPA项目说说RPC和MQ的使用。
  • 【大模型面试每日一题】Day 21:对比Chain-of-Thought(CoT)与Self-Consistency在复杂推理任务中的优劣
  • UUG杭州站 | 团结引擎1.5.0 OpenHarmony新Feature介绍
  • Vue3——父子组件通信
  • 游戏引擎学习第276天:调整身体动画
  • 从开发者角度看数据库架构进化史:JDBC - 中间件 - TiDB
  • Mipsel固件Fuzzing小记
  • 本土DevOps革命:Gitee如何撬动中国企业的数字化转型新动能
  • 关于此站点更改通知.top域名后期将统一更换为snowytime.cn访问,其余top访问进入过渡期
  • 使用python进行人员轨迹跟踪
  • 强化学习入门:马尔科夫奖励过程二
  • JVM 双亲委派机制
  • uniapp -- uCharts 仪表盘刻度显示 0.9999999 这样的值问题处理。
  • BGP团体属性
  • Redis——三大策略
  • Windows 操作系统使用 Tcping 命令检查目标主机端口是否开放
  • 序列化和反序列化:从理论到实践的全方位指南
  • PDF Base64格式字符串转换为PDF文件临时文件
  • 开源RTOS(实时操作系统):nuttx 编译
  • python打包exe报错:处理文件时错误:Excel xlsx file; not supported
  • VUE3 -综合实践(Mock+Axios+ElementPlus)
  • NDS3211HV单路H.264/HEVC/HD视频编码器
  • LeetCode热题100--206.反转链表--简单
  • 来一个复古的技术FTP
  • OpenCV CUDA模块中矩阵操作------分布统计类
  • OpenWebUI新突破,MCPO框架解锁MCP工具新玩法
  • go.mod关于go版本异常的处理
  • TRTC实时对话式AI解决方案,助力人机语音交互极致体验
  • Linux安全篇 --firewalld