您的數據和設置都是不正確。這裏列出了什麼是錯的,以及如何修復它們
1)dataDateFormat
用於解析字符串日期,不格式化它們。由於您使用的是unix時間戳,因此根本不需要此屬性,因此您可以將其刪除。
2)您的unix時間戳也必須以毫秒爲單位以使其工作。秒會給你無效的時間。
3)您的數據必須按日期升序排序才能正確呈現。您的數據目前處於混合順序。
至於你的其他問題:
要格式化您的日期,你必須在你的CategoryAxis的dateFormats
array設定爲所需的格式字符串作爲described here。對於DD/MM/YYYY:
"categoryAxis": {
// other properties omitted:
"dateFormats": [{period:'fff',format:'JJ:NN:SS'},
{period:'ss',format:'JJ:NN:SS'},
{period:'mm',format:'JJ:NN'},
{period:'hh',format:'JJ:NN'},
{period:'DD',format:'DD/MM/YYYY'}, //you may need to change the entries for 'WW' and 'MM' as well, depending on the amount of visible data
{period:'WW',format:'MMM DD'},
{period:'MM',format:'MMM'},
{period:'YYYY',format:'YYYY'}]
// ...
}
要在圖表上的負載自動變焦,您可以類似於一個rendered
事件添加到AmCharts網站上的演示如何做,並調用任何縮放方法,例如:
"listeners": [{
"event": "rendered",
"method": function(e) {
// different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues
e.chart.zoomToDates(new Date(2017, 1, 1), new Date(2017, 1, 15));
}
}]
下面是更新後的codepen與所有上述修復程序here。
它看起來像amCharts期望一個實際的Javascript日期對象。嘗試將unix時間戳更改爲日期:http://stackoverflow.com/questions/847185/convert-a-unix-timestamp-to-time-in-javascript – stderr
@stderr - Unix時間戳受支持,但它們需要在毫秒 – xorspark