带有解析为amCharts的时间或时间戳的JSON [英] JSON with parsed time or timestamp to amCharts

查看:119
本文介绍了带有解析为amCharts的时间或时间戳的JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些关于JSON和日期解析的新手问题.

I have some newbie questions about JSON and dates parsing.

我从服务器收到JSON响应,其中包含将时间戳转换为日期/时间,然后将其缓存.我认为直接在服务器上转换时间戳将利用客户端的脚本. 因此,我做到了,并且得到了服务器的响应,如下所示:

I have a JSON response from my server which contain converted timestamp to date/time, and then it's cached. I thought converting timestamp directly on server would leverage script on client side. So i did that and i had response from server like this:

[
  {"datetime": "2014/05/12 16:00", 
   "data": "172.0",
   "data2": "192",
   "data3": "172.0"
  },
  {...}
]

然后将这个JSON文件提取到amCharts,在Chrome中工作正常,而在Firefox和Safari中,则无法解析此类日期,并且出现错误.

This JSON file is then fetched to amCharts, in Chrome works perfectly fine, while in Firefox and Safari won't parse date like that and i get errors.

然后我将服务器的JSON响应更改为此:

Then i changed JSON response from server to this:

[
  {"datetime": 1213214234, 
   "data": 172.0,
   "data2": 192,
   "data3": 172.0      
  },
  {...}
]

我如何使用amCharts处理时间戳,或者如何为第一个示例制定解决方法? 并且因为我的json文件包含2000多个数据集,所以转换服务器上的时间戳记是一种好习惯吗?

How can i handle timestamp with amCharts or can make a workaround for first example? And is it good practice to convert timestamps on server, because my json file contain over 2000 data sets?

谢谢.

推荐答案

AmCharts可以将日期作为时间戳进行处理(无需执行其他操作),还可以使用几乎任何日期格式将日期设置为字符串.如果日期是字符串,则应设置chart.dataDateFormat ="YYYY/MM/DD JJ:NN";

AmCharts can handle dates as timestamps (no additional action is required), and also can handle dates set as strings using almost any date format. If your dates are strings, you should set chart.dataDateFormat = "YYYY/MM/DD JJ:NN";

在此处检查模式列表: http://www.amcharts.com/tutorials/格式化日期/

Check the list of patterns here: http://www.amcharts.com/tutorials/formatting-dates/

这篇关于带有解析为amCharts的时间或时间戳的JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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