Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
520 views
in Technique[技术] by (71.8m points)

highcharts - xAxis - point specific label positions

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 :

enter image description here

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 
    }
},
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...