简体   繁体   English

Angular 7 High Charts Stock Chart Datetime X Axis 工具提示格式独立于其他工具提示

[英]Angular 7 High Charts Stock Chart Datetime X Axis tooltip formatting independently of other tooltips

I'm working with high charts in angular 7, and am wanting to format the date in just the x-axis tooltip, and I want to leave the others alone entirely.我正在使用角度为 7 的高图表,并且只想在 x 轴工具提示中格式化日期,我想完全不理会其他人。

I was able to get the formatting I wanted in the x-axis tooltip, but it also broke the other two.我能够在 x 轴工具提示中获得我想要的格式,但它也破坏了其他两个。 I have two series in the y-axis, and those we've formatted when inserting the series, but I've seen little to no documentation.我在 y 轴上有两个系列,以及我们在插入系列时格式化的系列,但我几乎没有看到任何文档。 The solution that formatted the one and broke the others was from this question:格式化一个并打破其他的解决方案来自这个问题:

SO Quesrtion with Datetime Tooltip formatting. 带有日期时间工具提示格式的 SO 问题。

so I did my formatter like this:所以我这样做了我的格式化程序:

tooltip:{
  enabled: true,
  split: true,
  formatter: function() {return [moment(this.x).format('MMDDYY HH:00-HH:59')].concat(...other tooltips)
}

what I want to do, which doesn't seem possible, is somehow just format the x-axis tooltip like this, but haven't seen results with this method:我想要做的,这似乎不可能,不知何故只是像这样格式化 x 轴工具提示,但还没有看到这种方法的结果:

xAxis: {
  type: 'datetime',
  tooltip: {
    enabled: true,
    formatter: function() {
      return moment(this.value).format('MMDDYY HH:00-HH:59');
    }
  }
}

The real trick is how do I get formatting for just the x-axis?真正的诀窍是如何只为 x 轴设置格式? and only the x-axis, as we already have the formatting we want for the y-axis tooltips in the series?并且只有 x 轴,因为我们已经有了系列中 y 轴工具提示所需的格式?

It is not working because there is no such thing as xAxis.tooltip .它不起作用,因为没有xAxis.tooltip类的东西。 There is just one tooltip, and you can modify it using the tooltip.formatter .只有一个工具提示,您可以使用tooltip.formatter修改它。 The string that will be returned by the tooltip.formatter will become the tooltip content, so that's the place where you can affect the x value. tooltip.formatter将返回的tooltip.formatter将成为工具提示内容,因此您可以在此处影响 x 值。


chartOptions: Highcharts.Options = {
...

   tooltip: {
      formatter() {
         return `xAxis value: ${moment(this.x).format('MM.DD.YY HH:00-HH:59')}, 
         yAxis value: ${this.y}`
      },
   },
}

API references: API参考:
https://api.highcharts.com/highcharts/tooltip.formatter https://api.highcharts.com/highcharts/tooltip.formatter

Live demo:现场演示:
https://stackblitz.com/edit/highcharts-angular-basic-line-frbdhg https://stackblitz.com/edit/highcharts-angular-basic-line-frbdhg

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

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