Highcharts约会一天 [英] Highcharts date off by one day

查看:94
本文介绍了Highcharts约会一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以毫秒为单位传递x轴,然后定义x轴为:

  xAxis:{ 
类型:'datetime'
},

然而,Highcharts似乎是没有得到x轴上的确切日期,而是关闭了一天。为了说明,把鼠标悬停在任何一个酒吧(在这篇文章的底部摆弄),你会看到Highcharts解释当天的情况,然后点击其中的任何一个,然后我有一个点击事件来提醒你实际的日期是什么应该是。注意它是如何关闭一天的。



这是Highcharts中的一个已知错误吗?任何解决方法?



这是我的小提琴: http ://jsfiddle.net/hohenheim/j8cTE/33/

解决方案

我相信你所需要做的就是格式/考虑UTC。 Highcharts默认为UTC(0)。 ( http://api.highcharts.com/highcharts#global )如果您更改为:
$ b

 函数appendAds(date1){
alert(new Date(date1).toUTCString());
$('#tableTitle')。html(< u> Info for+ timeConverter(date1)+:< / u>);
...
}

(fiddle) http://jsfiddle.net/j8cTE/34/



您会看到它添加了toUTCString()显示正确的日期。您可能希望将其转换为更令人愉快的内容,但请记住,如果不使用toUTCString(),则必须记住UTC。

更新:
我想解释一下,我使用了toUTCString(),因为它很快,而且我知道我头顶的东西。这种方法不适用于所有的东西,比如appendAds函数中的更深层的东西,因为它是一个字符串。为了解释UTC和日期格式,完整的解析和操作对于这篇文章来说太多了。但在网络上处理日期时,我会尽量回顾一些关键点。另请参阅MDN获取其他日期信息( https:/ /developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date )。


如果您需要准确的信息和/或日期逻辑,您需要知道您获得的日期格式(从服务器,数据库等...) - 例如,是否是UTC。然后,您需要考虑是否需要对其进行操作以进行显示(例如针对观看者浏览器的时区)。最后,如果该日期在内部使用,则需要考虑是否,何时以及何地需要再次将其转换(如适用)。


I'm passing in milliseconds for the x-axis and then defining the x-axis as:

    xAxis: {
        type: 'datetime'
    },

However, Highcharts seems to be not getting the exact date on the x-axis but is instead off by one day. To illustrate, hover over any of the bars (fiddle at the bottom of this post) and you will see what Highcharts interprets the day as but then click any of them and I have an on-click event to alert you what the actual date is supposed to be. Notice how it is off by one day.

Is this a known bug in Highcharts? Any workarounds?

Here is my fiddle: http://jsfiddle.net/hohenheim/j8cTE/33/

解决方案

I believe all you need to do is format/consider for UTC. Highcharts default is UTC (0). (http://api.highcharts.com/highcharts#global) if you change to this:

function appendAds(date1) {
   alert(new Date(date1).toUTCString());
   $('#tableTitle').html("<u>Info for " + timeConverter(date1) + ":</u>");
   ...
}

(fiddle) http://jsfiddle.net/j8cTE/34/

You will see that it shows correct date with that "toUTCString()" added. You will likely want to convert it to something more pleasant to read, but remember that you will have to keep UTC in mind if you don't use "toUTCString()".

UPDATE: I wanted to explain that I used "toUTCString()" since it was quick and something I knew off the top of my head. This method wouldn't work for all things, such as further down in your appendAds function since it is a string. To explain UTC and date formatting, parsing and manipulation in full would be too much for this post. But I will try to go over a few key points when dealing with dates on the web. Also, please see MDN for other date info (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date).

If you need accurate information and/or logic for dates, you will need to know the date format you get (from server, database, etc...) - whether it is UTC or not, for example. Then you need to consider if it needs to be manipulated for display (such as for the viewers browser's timezone). And finally, if that date is being used internally, you need to consider if, when, and where you need to convert it once again (as appropriate).

这篇关于Highcharts约会一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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