Echart柱状图:自定义tooltip浮窗内容-字符串模板

本文介绍了如何在ECharts中为折线图、柱状图等配置tooltip,通过不同的formatter参数实现多样化显示效果,如展示多系列数据及自定义样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

折线(区域)图、柱状(条形)图、K线图 : {a}(系列名称),{b}(类目值),{c}(数值), {d}(无)

详细可见官网:https://echarts.apache.org/zh/option.html#tooltip.formatter

配置项:

{
tooltip: {
  trigger: 'axis',
  axisPointer: {
    type: 'shadow'
  },
  textStyle: {
    fontSize: 12
  },
  formatter: `
    {b} <br/>
    {a}&nbsp;&nbsp;&nbsp;{c}<br />
  `
},
}

效果图:当存在多个系列数据时,使用{a}、{c}只会展示第一个系列!!!
在这里插入图片描述
配置项:

{
tooltip: {
  trigger: 'axis',
  axisPointer: {
    type: 'shadow'
  },
  textStyle: {
    fontSize: 12
  },
  formatter: `
    {b} <br/>
    {a0}&nbsp;&nbsp;&nbsp;{c0}<br />
    {a1}&nbsp;&nbsp;&nbsp;{c1}<br />
    {a2}&nbsp;&nbsp;&nbsp;{c2}<br />
  `                          
},
}

效果图:当存在多个系列数据时,可以使用{a0}表示第一个系列的数据,{a1}表示第二个系列的数据,以此类推!!!
在这里插入图片描述
配置项:

{
tooltip: {
  trigger: 'axis',
  axisPointer: {
    type: 'shadow'
  },
  textStyle: {
    fontSize: 12
  },
  formatter: `{b} <br/>
  <span style="background-color: red;display: inline-block; width: 8px;height: 8px; border-radius: 50%;margin-right: 4px;line-height: 12px"></span>
  {a0}&nbsp;&nbsp;&nbsp;{c0}<br />
  <span style="background-color: red;display: inline-block; width: 8px;height: 8px; border-radius: 50%;margin-right: 4px;line-height: 12px"></span>
  {a1}&nbsp;&nbsp;&nbsp;{c1}<br />
  <span style="background-color: red;display: inline-block; width: 8px;height: 8px; border-radius: 50%;margin-right: 4px;line-height: 12px"></span>
  {a2}&nbsp;&nbsp;&nbsp;{c2}<br />
  `
},
}

效果图:字符串模也可以直接使用字符串模板来书写自定义标签样式,例如没一项数据前的market标识!!!

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值