如何在 highcharts 中添加跨越多个刻度的自定义内容

How to add custom content that spans across multiple ticks in highcharts

我需要在我们的应用程序中开发如下内容。

除了 "Aggregate" 刻度文本外,我能够实现所有功能。 Here 是 fiddle 的代码。

series: [{
    upColor: 'green',
    color: 'red',
    data: [{
        name: 'a',
        y: 60
    }, {
        name: 'b',
        y: 100
    }, {
        name: 'c',
        y: 50
    }, {
        name: 'd',
        isIntermediateSum: true,
        color: 'blue'
    }, {
        name: 'e',
        y: -20
    }, {
        name: 'f',
        y: -80
    }, {
        name: 'h',
        isSum: true,
        color: 'yellow'
    }],
    dataLabels: {
        enabled: true
    },
    pointPadding: 0
}]

谁能帮我解决这个问题。

提前致谢。

编辑:

在尝试了不同的东西并在 Whosebug 上搜索之后,我也能够实现那条水平线:

Check this updated fiddle.

更新代码:

var htmlContent = `<div class="flex-parent">
<div class="flex-child-edge"></div>
<div class="flex-child-text">Aggregate Value</div>
<div class="flex-child-edge"></div>
</div>`;

Highcharts.chart('container', {
  chart: {
    type: 'waterfall'
  },

  title: {
    text: 'Highcharts Waterfall'
  },

  xAxis: {
    type: 'category',
    tickWidth: 1,
    tickLength: 30,
    title: {
      enabled: true,
      useHTML: true,
      text: htmlContent,

    }
  },

  yAxis: {
    title: {
      text: 'USD'
    }
  },

  legend: {
    enabled: false
  },

  tooltip: {
    pointFormat: '<b>${point.y:,.2f}</b> USD'
  },

  series: [{
    upColor: 'green',
    color: 'red',
    data: [{
      name: 'a',
      y: 60
    }, {
      name: 'b',
      y: 100
    }, {
      name: 'c',
      y: 50
    }, {
      name: 'd',
      isIntermediateSum: true,
      color: 'blue'
    }, {
      name: 'e',
      y: -20
    }, {
      name: 'f',
      y: -80
    }, {
      name: 'h',
      isSum: true,
      color: 'yellow'
    }],
    dataLabels: {
      enabled: true
    },
    pointPadding: 0
  }]
});
.flex-parent {
  display: flex;
  width: 300px;
  height: 20px;
  align-items: center;
}

.flex-child-edge {
  flex-grow: 2;
  height: 1px;
  background-color: #000;
  border: 0px #000 solid;
}

.flex-child-text {
  flex-basis: auto;
  flex-grow: 0;
  margin: 0px 5px 0px 5px;
  text-align: center;
}
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; max-width: 600px; height: 400px; margin: 0 auto"></div>

有关如何绘制水平线的详细信息,请参阅 this Whosebug question


旧答案

如果那些水平线不是那个优先项目,
那么你可以使用 xAxistitle 属性来实现类似的东西。

Check this Link to the fiddle.

像这样:

xAxis: {
  type: 'category',
  tickWidth: 1,
  tickLength: 30,
  title: {
    enabled: true,
    text: '<b>Aggregate Value<b>',
    style: {
      fontSize: '14',
      color: "#000000"
    }
  }
}