javascript - JSON with parsed time or timestamp to amCharts - Stack Overflow

I have some newbie questions about JSON and dates parsing.I have a JSON response from my server which c

I have some newbie questions about JSON and dates parsing.

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"
  },
  {...}
]

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.

Then i changed JSON response from server to this:

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

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?

Thanks.

I have some newbie questions about JSON and dates parsing.

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"
  },
  {...}
]

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.

Then i changed JSON response from server to this:

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

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?

Thanks.

Share Improve this question asked May 15, 2014 at 10:03 JackJack 1,5214 gold badges21 silver badges29 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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";

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

will it help you, if I suggest to convert timestamp to datetime with javascript?

var date = new Date(timestamp*1000);
datevalues = [
     date.getFullYear()
    ,date.getMonth()+1
    ,date.getDate()
    ,date.getHours()
    ,date.getMinutes()
    ,date.getSeconds()
 ];

I'm not sure will it help or not.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744337841a4569223.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信