【问题标题】:How to add custom content that spans across multiple ticks in highcharts如何在 highcharts 中添加跨越多个刻度的自定义内容
【发布时间】:2019-11-16 08:13:37
【问题描述】:

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

除了“聚合”文本之外,我能够实现所有目标。 Here 是要摆弄的代码。

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
}]

任何人都可以帮我解决这个问题。

提前致谢。

【问题讨论】:

  • 这是什么问题?
  • 我无法在 xaxis 标签下方添加 Aggregate 文本
  • 你也需要水平线吗?
  • 如果有帮助,别忘了点赞并将其标记为正确答案!

标签: javascript highcharts customization graph-visualization


【解决方案1】:

编辑:

在尝试了不同的方法并在 Stackoverflow 上进行搜索后,我也能找到那条水平线:

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 stackoverflow 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"
    }
  }
}

【讨论】:

  • 非常感谢。那行得通。但是缺少的一件事是我们想要指定标题应该从哪个刻度开始并在哪个位置结束,我们可以这样做吗,就像我添加的图像一样,它应该从 b 跨越到 f。
猜你喜欢
  • 2014-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-30
  • 2021-12-13
  • 1970-01-01
  • 1970-01-01
  • 2015-06-22
相关资源
最近更新 更多