获取高图滚动条的左侧和顶部位置 [英] Get left and top position of highcharts scrollbar

查看:84
本文介绍了获取高图滚动条的左侧和顶部位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在高图上放置自定义标签,该标签应放在左侧 滚动条的一侧.如何获得滚动条的顶部和左侧位置??

I wanted to put custom label on highcharts which should be placed on left side of scrollbar. How can I get top and left position of scrollbar.?

我用以下代码放置了标签

I have put label with following code

chart.renderer.text('<span style="font-weight:600;"> 1-21 </span>', 20, 120)
        .css({
            color: 'green',
            fontSize: '12px'
        })
        .add();

推荐答案

您可以使用chart.xAxis[0].scrollbar.group.translateXchart.xAxis[0].scrollbar.group.translateY获取滚动条的位置,例如:

You can get position of the scrollbar using chart.xAxis[0].scrollbar.group.translateX and chart.xAxis[0].scrollbar.group.translateY, for example: https://codepen.io/anon/pen/KeBxNj?editors=1010

摘要:

var chart = Highcharts.chart('container', {
  chart: {
    type: 'bar',
    marginLeft: 150,
    events: {
      load: function () {
        var scrollbar = this.xAxis[0].scrollbar,
            bbox;
        // Render:
        this.customLabel = this.renderer.text('<span style="font-weight:600;"> 1-21 </span>', 0, 0).attr({
          zIndex: 5
        }).add();
        // Get bbox
        bbox = this.customLabel.getBBox();

        // Position label
        this.customLabel.attr({
          x: scrollbar.group.translateX - bbox.width,
          y: scrollbar.group.translateY + bbox.height
        });
      }
    }
  },
  ...
});

这篇关于获取高图滚动条的左侧和顶部位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆