xAxis-点特定的标签位置

时间:2018-08-02 15:05:09

标签: highcharts

有没有一种方法可以对xAxis标签进行特定点定位?

我正在使用瀑布图,对于某些条,我希望标签直接显示在下面的条下面:

enter image description here

我在xAxis plotOptions中找到了以下代码,但目前我还看不到如何在图表底部访问信息。

def pick_sql_version():  # might be redundant

    # create an easy list to pick from
    sql_year = ['2008', '2014', '2016']
    for i, val in enumerate(sql_year, start= 1):
        print("{} SQL Server Management Studio {}".format(i, val))
    sql_version = input("Pick the SSMS version: ")

    # depending on the sql version path might vary
    version_d = {
        '1': '120',
        '2': '130'
    }

    # If invalid path is chosen fall back to default (120)
    t='C:/Program Files (x86)/Microsoft SQL Server/{}/Tools/Binn/ManagementStudio/Ssms.exe'
    path = t.format(version_d.get(sql_version, '120'))

    return path

1 个答案:

答案 0 :(得分:0)

您可以使用点数据标签来获得这样的结果:

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

实时演示:https://jsfiddle.net/BlackLabel/71jtp5mf/

API参考:https://api.highcharts.com/highcharts/series.waterfall.dataLabels

另一种方法是创建自己的自定义函数来放置xAxis标签,例如:

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
        })
      }
    });
  }
}

实时演示:https://jsfiddle.net/BlackLabel/oaj9bgt4/