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

Echarts图表坐标轴文字太长,省略显示,鼠标放上显示全部(vue)

注意:记得加上这个,触发事件, triggerEvent: true,
重点:下面就是处理函数,在实例化图表的时候使用,传入参数是echarts的实例

// 渲染echartsfirstBarChart() {const that = thislet columnar = echarts.init(that.$refs.bar1)columnar.setOption({tooltip: {trigger: 'axis',axisPointer: {// 坐标轴指示器,坐标轴触发有效type: 'shadow', // 默认为直线,可选为:'line' | 'shadow'},},grid: {top: '3%',right: '3%',bottom: '3%',left: '0%',// 包含文本containLabel: true,// 是否显示网格线show: true,// 边框颜色borderColor: 'rgba(0, 240, 255, 0.3)',},xAxis: [{type: 'category',data: that.xmNameData,// 不要刻度axisTick: {alignWithLabel: false,show: false,},// 记得加上这个triggerEvent: true,axisLabel: {color: '#4c9bfd', // 文字颜色rotate: 45, // 文字倾斜// 文字省略formatter: function (value) {if (value.length > 3) {return `${value.slice(0, 3)}...`}return value},},},],yAxis: [{type: 'value',// 不要刻度axisTick: {alignWithLabel: false,show: false,},// 文字颜色axisLabel: {color: '#4c9bfd',},// 分割线splitLine: {lineStyle: {color: 'rgba(0, 240, 255, 0.3)',},},},],series: [{name: ' 完成投资比例',type: 'bar',barWidth: '60%',data: that.wcblData,label: {show: true,position: 'inside',},// 颜色itemStyle: {color: new echarts.graphic.LinearGradient(// (0,0)点到(0,1)0,0,0,1,[{ offset: 0, color: 'red' }, // 0 起始颜色{ offset: 1, color: 'blue' }, // 1 结束颜色,]),},},],})// 就是这个方法,解决放上提示全部that.extension(columnar)columnar.on('click', function (data) {// 添加点击事件})},
extension(chart) {// 注意这里,是以X轴显示内容过长为例,如果是y轴的话,需要把params.componentType == 'xAxis'改为yAxis// 判断是否创建过div框,如果创建过就不再创建了// 该div用来盛放文本显示内容的,方便对其悬浮位置进行处理var elementDiv = document.getElementById('extension')if (!elementDiv) {var div = document.createElement('div')div.setAttribute('id', 'extension')div.style.display = 'block'document.querySelector('html').appendChild(div)}chart.on('mouseover', function (params) {if (params.componentType == 'xAxis') {var elementDiv = document.querySelector('#extension')//设置悬浮文本的位置以及样式var elementStyle ='position: absolute;z-index: 99999;color: #fff;font-size: 12px;padding: 5px;display: inline;border-radius: 4px;background-color: #303133;box-shadow: rgba(0, 0, 0, 0.3) 2px 2px 8px'elementDiv.style.cssText = elementStyleelementDiv.innerHTML = params.valuedocument.querySelector('html').onmousemove = function (event) {var elementDiv = document.querySelector('#extension')var xx = event.pageX - 10var yy = event.pageY + 15console.log('22', xx)elementDiv.style.top = yy + 'px'elementDiv.style.left = xx + 'px'}}})chart.on('mouseout', function (params) {//注意这里,我是以X轴显示内容过长为例,如果是y轴的话,需要改为yAxisif (params.componentType == 'xAxis') {var elementDiv = document.querySelector('#extension')elementDiv.style.cssText = 'display:none'}})},

 

http://www.lryc.cn/news/147939.html

相关文章:

  • C语言控制语句——跳转关键字
  • C#,《小白学程序》第五课:队列(Queue)
  • 【【萌新的STM32学习25--- USART寄存器的介绍】】
  • SpringBootWeb案例 Part 5
  • 【ES6】Promise.race的用法
  • PMP - 敏捷 3355
  • Mapbox-gl 关闭所有Popup,以及关闭按钮出现黑色边框bug
  • RE:从零开始的车载Android HMI(四) - 收音机刻度尺
  • 评估安全 Wi-Fi 接入:Cisco ISE、Aruba、Portnox 和 Foxpass
  • java 泛型作为方法的返回值的封装
  • ASP.NET Core 中基于 Minimal APIs 的Web API
  • Unity ProBuilder SetUVs 不起作用
  • c#接口(interface)
  • SSH远程连接macOS服务器:通过cpolar内网穿透技术实现远程访问的设置方法
  • 【C++】Visual Studio EditorConfig 格式设置
  • 服务器单机大规模数据存储方案
  • ElasticSearch-集成ik分词器
  • c++版opencv求二值图的质心
  • 6、深入解析Kotlin类与对象:构造、伴生、单例全面剖析
  • 【开源ESP32谷歌恐龙小游戏】【游戏演示和介绍】LVGL ST7789 适用于Arduino
  • openCV实战-系列教程7:轮廓检测2与模板匹配(轮廓检测/轮廓特征/轮廓近似/轮廓边界矩阵/轮廓边界圆/模版匹配)、原理解析、源码解读
  • cs231n_1_IntroToConv
  • OPENCV实现SURF特征检测
  • Android Gradle 同步优化
  • BeautifulSoup:学习使用BeautifulSoup库进行HTML解析和数据提取。
  • 基于沙猫群算法优化的BP神经网络(预测应用) - 附代码
  • PCL 判断三点共线(三维空间)
  • 【数据库】事务(概念和特点)
  • LA@齐次线性方程组解的结构
  • Docker修改容器ulimit的全部方案及各方案的详细步骤