xAxis - point specific label positions

杀马特。学长 韩版系。学妹 提交于 2021-02-11 14:55:29

问题


Is there a way to have a point specific positionning of the xAxis labels ?

I am using a waterfall chart and for some bars I would like the label to appear directly under the bar like below :

I have found the following code in the xAxis plotOptions but at this point I don't see how I can acces the info on the bottom of the chart.

xAxis: {
    labels: {
        y:-100 //label's y position 
    }
},

回答1:


You can use point dataLabels to achieve such result:

dataLabels: {
    crop: false,
    overflow: 'none',
    verticalAlign: 'bottom',
    format: 'label1',
    y: 20
}

Live demo: https://jsfiddle.net/BlackLabel/71jtp5mf/

API Reference: https://api.highcharts.com/highcharts/series.waterfall.dataLabels

Another way is to create your own custom function to position the xAxis labels, for example:

events: {
  load: function() {
    var chart = this,
      point;

    Highcharts.objectEach(chart.xAxis[0].ticks, function(tick) {
      if (!tick.isNewLabel) {
        point = chart.series[0].points[tick.pos];
        tick.label.attr({
          y: point.plotY + chart.plotTop + point.shapeArgs.height + 15
        })
      }
    });
  }
}

Live demo: https://jsfiddle.net/BlackLabel/oaj9bgt4/



来源:https://stackoverflow.com/questions/51656849/xaxis-point-specific-label-positions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!