问题
How can we parse the amcharts stock dates?
Here example datas:
chartData1=[{
'date':'01-09-2010,00:05:05',
'value':1,
'volume':1
},{
'date':'01-10-2010,00:05:05',
'value':1,
'volume':1
},{
'date':'01-11-2010,00:05:05',
'value':1,
'volume':1
},{
'date':'02-07-2010,00:05:05',
'value':1,
'volume':1
},{
'date':'02-11-2010,00:05:05',
'value':1,
'volume':1
},{
'date':'03-07-2010,00:05:05',
'value':2,
'volume':2
},{
'date':'03-08-2010,00:05:05',
'value':2,
'volume':2
},{
'date':'04-08-2010,00:05:05',
'value':1,
'volume':1
},{
'date':'04-09-2010,00:05:05',
'value':1,
'volume':1
}];
When use it like this the dates from and to time period coming from like this:
From
29-10-1920
To
30-10-1920
How can I fix this error with parsing dates?
Thanks
回答1:
Simply set chart.dataDateFormat = "DD-MM-YYYY,JJ:NN:SS"
回答2:
I ran into the same problem as you and the only way I got around this was to use Javascript date objects instead of date strings.
Instead of writing
'date':'01-09-2010,00:05:05'
I write is as
'date': new Date(2010, 09, 01, 00, 05, 05, 00)
I looked through the amCharts website for their Stock Chart demos they only use date objects instead of date strings: http://www.amcharts.com/tutorials/your-first-stock-chart/
It looks like the plugin doesn't parse date strings correctly. For regular amCharts it works fine with the chart.dataDateFormat option, but not for the Stock Charts in my testing.
回答3:
First you have to set the dataformat for the category axis, as per your requirement it is set to following format:
chart.dataDateFormat = "DD-MM-YYYY,JJ:NN:SS"
Then you have to define whether you want to display your data daily, hourly, or every minute. Default setting is daily, for hourly you can use
categoryAxesSettings.minPeriod = "hh"
For more details visit https://www.amcharts.com/tutorials/formatting-dates/
回答4:
In addition to setting the date format for the category axis, you also have to set parseDates for category Axis to true if you're using date objects for your categoryAxis.
来源:https://stackoverflow.com/questions/27745718/how-to-parse-amcharts-stock-dates