highcharts-为缺少的列添加标签

highcharts-为缺少的列添加标签,highcharts,Highcharts,在我的图表中,我有一个值为-1的列。这表示此系列的值不可用 在图表中,我想添加一个旋转90度的标签,上面写着“无数据”栏应该在哪里。有人能给我举个例子说明如何做到这一点吗 如果列的值为-1,则仍将呈现该列。您需要将-1值映射为null。之后,可以使用函数为空列呈现旋转文本 用于呈现/重画标签的函数: function renderLabels() { this.series[0].points.forEach((point, i) => { if (point.is

在我的图表中,我有一个值为-1的列。这表示此系列的值不可用


在图表中,我想添加一个旋转90度的标签,上面写着“无数据”栏应该在哪里。有人能给我举个例子说明如何做到这一点吗

如果列的值为-1,则仍将呈现该列。您需要将-1值映射为null。之后,可以使用函数为空列呈现旋转文本

用于呈现/重画标签的函数:

  function renderLabels() {
    this.series[0].points.forEach((point, i) => {
      if (point.isNull) {
        point.noDataLabel = this.renderer.text('No data', 0, -9e9).attr({
          rotation: 90,
          zIndex: 99
        }).add()
      }
    })

    redrawLabels.call(this)
}

function redrawLabels() {
  this.series[0].points.forEach(point => {
    if (point.noDataLabel) {
      point.noDataLabel.attr({
        x: point.series.group.translateX + point.plotX,
        y: this.plotTop + this.plotHeight - 80
      })
    }
  })
}
加载和重画事件时附加函数,以及映射数据:

Highcharts.chart('container', {
    chart: {
        type: 'column',
        events: {
          load: renderLabels,
          redraw: redrawLabels
        }
    },
    series: [{
        data: data.map(v => v === -1 ? null : v)
    }]
});
示例和输出


如果列的值为-1,则仍将呈现该列。您需要将-1值映射为null。之后,可以使用函数为空列呈现旋转文本

用于呈现/重画标签的函数:

  function renderLabels() {
    this.series[0].points.forEach((point, i) => {
      if (point.isNull) {
        point.noDataLabel = this.renderer.text('No data', 0, -9e9).attr({
          rotation: 90,
          zIndex: 99
        }).add()
      }
    })

    redrawLabels.call(this)
}

function redrawLabels() {
  this.series[0].points.forEach(point => {
    if (point.noDataLabel) {
      point.noDataLabel.attr({
        x: point.series.group.translateX + point.plotX,
        y: this.plotTop + this.plotHeight - 80
      })
    }
  })
}
加载和重画事件时附加函数,以及映射数据:

Highcharts.chart('container', {
    chart: {
        type: 'column',
        events: {
          load: renderLabels,
          redraw: redrawLabels
        }
    },
    series: [{
        data: data.map(v => v === -1 ? null : v)
    }]
});
示例和输出


请阅读“如何创建最小、完整和可验证的示例”:请阅读“如何创建最小、完整和可验证的示例”: