highcharts tooltip分列以及x轴某类的合计

下面代码是tooltip分列以及x轴某类的合计。图片是formatter函数中的this所指内容,x是x轴某类,points是这个类有多少种,每个里面是一个对象,包含颜色数值等

tooltip: {
            shared: true,
            useHTML: true,
            formatter: function(){
            // 这是将数据进行分列,去掉数据为0的数据以及合计
              let tmp = '';
              // let length = this.points.length;//数据条数,this.points获取的是当前x轴刻度上的数据信息
              // 先是获取不为0的数据
              let pointList = this.points.filter(i => i.y > 0)
              let length = pointList.length
              let rowCount = 10;//一列允许的最大行数
              // 判断有多少列
              let lineCount = parseInt(length / rowCount) + 1;//列数
             // 将鼠标悬浮的数据进行汇总,即合计
              let sum = 0
              pointList.map(i => {
                sum += i.y
              })
              // 写在最上面的合计。也可以this.x加合计
              tmp += '<span style="font-size:10px">合计:'+sum+'个</span><table><table>';
             // 竖着排序。显示的时候是0和10在一行,分为两列
              for (let i = 0; i < rowCount; i++) {
                tmp += "<tr>";
                for (let j = 0; j < lineCount && j * rowCount + i  < length; j++) {
                  let it = pointList[j * rowCount + i];
                    tmp += "<td style='padding-right: 17px;'><span style='color:" + it.color + "'>● " + it.series.name + ":</span><span style='font-weight: bold'>" + it.y + "个</span></td>";
                }
                tmp += '</tr>';
              }
              tmp += '</table>';
              return tmp;
            },
          },

// head + 每个 point + footer 拼接成完整的 table;这是一个简单的显示x轴某一项的所有数据(分开显示);headerFormat、pointFormat只能跟字符串;pointFormat有回调函数,其代表的this只能是x上的一种不能求合计
            // headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            // pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
            // '<td style="padding:0"><b>{point.y} 个</b></td></tr>',
            // footerFormat: '</table>',

在这里插入图片描述

参考文章
https://www.cnblogs.com/liumaowu/p/12206082.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值