用html自定义横向条形图

// 进度条图表
function progressCharts(interfaceCharts, list) {
  var html = '<div id="progress_inner" class="progress-inner">', artArr=[], max=0;
  // 获取最大值
  for(var i=0; i<list.length; i++) {
    artArr.push(list[i].art);
  }
  max = Math.max.apply(null,artArr);
  // 构造图表
  for(var i=0; i<list.length; i++) {
    html += `<div class="progress-item"><div class="clearfix progress-top">
      <span class="fl custom-time">${list[i].dateTime}</span><span class="fl">${list[i].method}</span><span class="fr fa fa-file-text custom-jump" data-m="${list[i].method}"></span>
    </div>
    <div class="custom-line"><div class="custom-line-bar" data-method="${list[i].method}" data-time="${list[i].dateTime}" data-art="${list[i].art}" data-w="${(list[i].art/max)*100}%" style="width:0"></div></div></div>`
  }
  html += '</div>';

  $('#'+interfaceCharts).html(html);
  setTimeout(() => {
    $('.custom-line-bar').each(function(i, item) {
      $(this).css({'width': $(this).attr('data-w'), 'transition': 'width 2s', '-webkit-transition': 'width 2s'})
    })
  }, 300);


  $('#progress_inner .custom-line').mouseover (function(e) {
    var e = e || window.event;
    if($('#custom_tip').length>0) {
      return;
    }

    var html = `<div id="custom_tip" class="custom-tip" style="left: ${e.clientX + 5 + 'px'}; top: ${e.clientY - 80 + 'px'}">
    <P><span class="custom-point"></span>${$(this).find('.custom-line-bar').attr('data-time')}</P>
    <P><span class="custom-point"></span>${$(this).find('.custom-line-bar').attr('data-method')}</P>
    <P><span class="custom-point"></span>${$(this).find('.custom-line-bar').attr('data-art')}</P>
    </div>`;
    $('#progress_inner').append(html);

    $(this).mousemove(function(ev) {
      var e = ev || window.event;
      $('#custom_tip').css({'left': e.clientX + 5 + 'px', 'top': e.clientY - 80 + 'px'});
    }) 
  })


  $('#progress_inner .custom-line').mouseout(function() {
    $('#custom_tip').remove();
  })

  $('#progress_inner .custom-jump').click(function() {
    tranDetail($(this).attr('data-m'));
  })
    
}

知识点: 鼠标移上显示信息提示框,并跟随鼠标移动

  $('#progress_inner .custom-line').mouseover (function(e) {
    var e = e || window.event;
    if($('#custom_tip').length>0) {
      return;
    }

    var html = `<div id="custom_tip" class="custom-tip" style="left: ${e.clientX + 5 + 'px'}; top: ${e.clientY - 80 + 'px'}">
    <P><span class="custom-point"></span>${$(this).find('.custom-line-bar').attr('data-time')}</P>
    <P><span class="custom-point"></span>${$(this).find('.custom-line-bar').attr('data-method')}</P>
    <P><span class="custom-point"></span>${$(this).find('.custom-line-bar').attr('data-art')}</P>
    </div>`;
    $('#progress_inner').append(html);

    $(this).mousemove(function(ev) {
      var e = ev || window.event;
      $('#custom_tip').css({'left': e.clientX + 5 + 'px', 'top': e.clientY - 80 + 'px'});
    }) 
  })


  $('#progress_inner .custom-line').mouseout(function() {
    $('#custom_tip').remove();
  })

结果如下图

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值