简体   繁体   English

如何在highchart中将标题html div与图表水平对齐?

[英]How to align title html div with chart horizontally in highchart?

Consider the following jsfiddle 考虑以下jsfiddle

在此处输入图片说明

I am trying to align the gap between title bottom-border and the chart. 我正在尝试调整标题bottom-border和图表之间的差距。 Preferably the left side and right side of the chart aligns with the left side and right side of title border respectively. 优选地,图表的左侧和右侧分别与标题边框的左侧和右侧对齐。

Is there anyway I can do that without hardcoding (my chart width changes relative to screen size)? 无论如何,我可以不用硬编码就能做到这一点(我的图表宽度相对于屏幕大小发生变化)吗?

You can force the title to have the same width and left offset as the plot area. 您可以强制标题具有与绘图区域相同的宽度和左偏移。 To make sure it's responsive use the render event: 为了确保它是响应式的,请使用render事件:

chart: {
  plotBorderWidth: 1,
  events: {
    render: function() {
      var style = this.title.element.style;
      style.left = this.plotLeft + 'px';
      style.width = this.plotWidth + 'px';
    }
  }
}

Live working demo: http://jsfiddle.net/kkulig/y3fj6vpq/ 现场工作演示: http //jsfiddle.net/kkulig/y3fj6vpq/

API reference: https://api.highcharts.com/highcharts/chart.events.render API参考: https //api.highcharts.com/highcharts/chart.events.render

Change these two properties of the title. 更改标题的这两个属性。

left: 77px;
width: 922px;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM