javascript 在 HighCharts 中获取 X 轴值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7178811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting the X Axis value in HighCharts
提问by Hadleigh
I am trying to get the actual value of the x axis into a string but I can't work out the syntax.
我试图将 x 轴的实际值转换为字符串,但我无法计算出语法。
I have just started to develop a demonstration version of the HighCharts, so the example below is what I am altering:
我刚刚开始开发 HighCharts 的演示版本,所以下面的例子是我正在改变的:
http://www.highcharts.com/demo/line-ajax/grid
http://www.highcharts.com/demo/line-ajax/grid
(press options to see the code behind this)
(按选项查看这背后的代码)
I am trying to change the following line of code
我正在尝试更改以下代码行
maincontentText: Highcharts.dateFormat('%A, %b %e, %Y', this.x) +':<br/> '+ this.y +' visits',
maincontentText: Highcharts.dateFormat('%A, %b %e, %Y', this.x) +':<br/> '+ this.y +' visits',
This is because my data x axis value is a Month name. Therefore I want to say something like:
这是因为我的数据 x 轴值是月份名称。因此,我想说:
maincontentText: this.x.value +': '+ this.y +' visits',
maincontentText: this.x.value +': '+ this.y +' visits',
It's probably very simple, does anyone know why every permutation I try has failed?
这可能很简单,有谁知道为什么我尝试的每个排列都失败了?
Thanks :-)
谢谢 :-)
回答by eolsson
The example you started with has a numeric x-axis, a timeline, this.x
will be a number (milliseconds from jan 1, 1970) suitable for Highcharts.dateFormat
.
您开始的示例有一个数字 x 轴,一个时间轴,this.x
将是一个适合Highcharts.dateFormat
.
If you have changed the example to use a categorical x-axis, then you instead find the category in this.category
so I think this will work:
如果您已将示例更改为使用分类 x 轴,那么您可以在其中找到类别,this.category
因此我认为这会起作用:
maincontentText: this.category +': '+ this.y +' visits',
maincontentText: this.category +': '+ this.y +' visits',
Example: here
例子:这里