tickInterval在Highchart和Highstock中无法正常工作。 [英] tickInterval doesn't work properly in Highchart and Highstock.

查看:107
本文介绍了tickInterval在Highchart和Highstock中无法正常工作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Highstock / Highchart来显示一些数据。在我的数据中,每个记录之间的时间间隔为1毫秒,我想将每个时间间隔的长度设置为40毫秒,我通过将tickInterval设置为40来尝试,但在图上它显示了每个记号之间的50。如果我将它设置为30,图表显示为25.非常奇怪,我不知道该怎么做,请帮助。

连结:
http:// jsfiddle.net/xEcNS/1/



感谢您

解决方案

我经历了highstock源代码,发现这段代码

  function normalizeTimeTickInterval(tickInterval,unitsOption){
var units = unitsOption || [[
MILLISECOND,//单位名称
[1,2,5,10,20,25,50,100,200,500] //允许倍数
...

这段代码是什么?
它说,如果你的时间单位是毫秒,然后标准化tickInterval(40,在你的情况下)为其中的一个倍数,因此它正常化40至50和30至25我看不到如果这可以从选项中覆盖。您可以选择更改代码,但前提是您可以接受并且不违反任何版权法。


编辑:找到一个黑客得到这个工作,而无需更改源代码
check fiddle @ http://jsfiddle.net/jugal / H83bs /



这就是我所做的。对源代码的一点调试/分析提示Highchart首先尝试在轴的选项的单位属性中查找单位事物,如果它找不到它,它将使用默认值。所以我继续并调整单位属性设置如下。您需要在调用highcharts构造函数之前执行此操作。

  Highcharts.Axis.prototype.defaultOptions.units = [[
'毫秒',
[1,2,5,10,20,25,30,40,50,100,200,500]
],[
'秒',
[1,2,5,10,15,30]
],[
'分钟',
[1,2,5,10,15,30]
],[
'小时',
[1,2,3,4,6,8,12]
],[
'日',
[1]
],[
'周',
[1]
],[
'月',
[1,3 ,6]
],[
'year',
null
]];


I am trying to use Highstock/Highchart to show some data. In my data, the interval between each record is 1 millisecond, I want to set length between each tick to 40 milliseconds, I tried it by setting tickInterval to 40, but on the graph it shows 50 between each tick. If I set it to 30, the graph shows 25. Very weird, I don't know what to do now, please help.

The link: http://jsfiddle.net/xEcNS/1/

Thanks you

解决方案

I went through the highstock source code and found this piece of code

function normalizeTimeTickInterval(tickInterval, unitsOption) {
 var units = unitsOption || [[
 MILLISECOND, // unit name
 [1, 2, 5, 10, 20, 25, 50, 100, 200, 500] // allowed multiples 
 ...
}

What is this code? It says if the units of your time is milliseconds, then normalize the tickInterval (40, in your case) to a multiple of one of these, hence it normalizes 40 to 50 and 30 to 25. I don't see if this can be overridden from options. You do have an option of changing the code though, if that is acceptable to you and do not violate any copyright laws.

EDIT: Found a hack to get this working without changing source code check fiddle @ http://jsfiddle.net/jugal/H83bs/

Here is what I did. A little debugging/analysis of source code gave the hint that highchart first tries to find the units thing in the axis's options's units property, if it doesn't find it, it uses the default one. So I went ahead and tweaked the units property to set it as follows. You will need to do this before calling the highcharts constructor.

Highcharts.Axis.prototype.defaultOptions.units=[[
            'millisecond',
            [1, 2, 5, 10, 20, 25,30,40, 50, 100, 200, 500]
        ], [
            'second',
            [1, 2, 5, 10, 15, 30]
        ], [
            'minute',
            [1, 2, 5, 10, 15, 30]
        ], [
            'hour',
            [1, 2, 3, 4, 6, 8, 12]
        ], [
            'day',
            [1]
        ], [
            'week',
            [1]
        ], [
            'month',
            [1, 3, 6]
        ], [
            'year',
            null
        ]];

这篇关于tickInterval在Highchart和Highstock中无法正常工作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆