문제

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.

도움이 되었습니까?

해결책

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.com/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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top