javascript - 获取highcharts柱形图中每个条形的终点

标签 javascript jquery highcharts

我正在尝试创建一个条形图,每个条形末端的箭头指向下一个条形。为此,我需要知道每个柱的终点坐标。请引用下图,以更清楚地了解我要实现的目标。 This is what I am trying to achieve

我现在的方法是在图表对象中获取每个 series[0].points[i] 中的 clientX,并将其与 plotWidth 添加到我需要渲染箭头图像的位置。现在这似乎不起作用,因为箭头呈现不正确。我现在的方法在这里很麻烦。我试图在每个小节的末尾获得“X”,现在它出现在中间的某个地方。

这是问题的 jsfiddle - http://jsfiddle.net/qp90yx34/1/

这是我现在所在位置的代码 -

$(function () {
  $('#container').highcharts({
    chart: {
      type: 'column',
      events: {
        load: function () {
          _.each(this.series[0].points, (point, key) => {
            if (!_.isUndefined(this.series[0].points[key + 1])) {
              this.renderer.text("X",
              point.clientX + point.pointWidth, //x
              point.plotY) // y
              .add();
            }
          })  
        },
      }
    },
    title: {
      text: '',
    },
    plotOptions: {
      series: {
        dataLabels: {
          enabled: false,
          format: '<b>{point.name}</b> ({point.y:,.0f})',
        },
      }
    },
    legend: {
      enabled: false
    },
    xAxis: {
      categories: ['Test 1', 'Test 2', 'Test 3', 'Test 4', 'Test 5']
    },
    series: [{
      type: 'column',
      name: 'Marks',
      data: [83, 72, 71, 63, 74]
    }]
  });
});

最佳答案

我认为您应该能够在 renderer.text 方法中更改文本的 x 位置:

      this.renderer.text("X",
          point.clientX + point.pointWidth / 2 + chart.plotLeft, //x
          point.plotY) // y
        .add();

在这个方法中,我添加了 chart.plotLeft,它是图表左边缘和 plotArea 之间的距离。

我还将 point.pointWidth 更改为 point.pointWidth/2 因为 point.clientX 是列中心的像素位置。

实例: http://jsfiddle.net/qp90yx34/2/

关于javascript - 获取highcharts柱形图中每个条形的终点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44328619/

相关文章:

javascript - 为什么 Promise.all 没有绑定(bind)到 Promise?

python - 如何最有效、最安全地模拟 Python shell?

jQuery 事件处理程序总是按照它们被绑定(bind)的顺序执行——有什么办法解决这个问题吗?

javascript - 如何在 jQuery 中获取屏幕上可见的元素对象?

javascript - 由 jQuery 触发时,不会触发使用 addEventListener() 添加的事件

java - 在 Windows 7 上的 Tomcat 7 中放置 phantomjs.exe 的位置

javascript - Highchart 中 X 轴排序错误

javascript - 在 Material <md-tab-group> 中使用 Angular 2 组件

javascript - 更新 colorAxis 后导出 Highcharts

javascript - 什么是跨域请求/跨域攻击/跨域协议(protocol)