当前位置:   article > 正文

ECharts修改tooltip样式_echarts tooltip文字更改

echarts tooltip文字更改

tooltip不支持rich,formatter返回的是html片段,可以在这个返回的片段里面增加类名。以达到更改tooltip文字格式的效果。所以,直接写html的样式就可以

静态数据

formatter: (params) => {
          console.log('params', params)
          return '<h2 style="font-size: 20px; color: aqua">ddddd</h2>'
        },
  • 1
  • 2
  • 3
  • 4

动态数据

法一:模板字符串

const test = ref('test')

 formatter: (params) => {
          console.log('params', params)
          return `<h2 style="font-size: 20px; color: aqua">${test.value}</h2>`
        },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

法二:官方字符串模板

在这里插入图片描述

formatter: '<h2 style="font-size: 20px; color: aqua">{b}</h2>',
  • 1

法三:回调函数

formatter: (params) => {
          console.log('params', params)
          return `<h2 style="font-size: 20px; color: aqua">${params.name}</h2>`
          //   return `<h2 style="font-size: 20px; color: aqua">${test.value}</h2>`
        },
  • 1
  • 2
  • 3
  • 4
  • 5

因为这里已经使用了回调函数,所以用params.xxx来获取对应的值,再使用{b}等字符串模板是不会生效的!!!!

顺道插一句这里的参数params
在这里插入图片描述

动态样式

就是在回调函数里直接写判断就可以 ,很简单!!!

 formatter: (params) => {
          console.log('params', params)
          if (params.name === '交通运输') {
            return `<h2 style="font-size: 20px; color: pink">${params.name}</h2>`
          } else return `<h2 style="font-size: 20px; color: black">${params.name}</h2>`
          //   return `<h2 style="font-size: 20px; color: aqua">${test.value}</h2>`
        },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

在这里插入图片描述在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/308747
推荐阅读
相关标签
  

闽ICP备14008679号