2
我試圖在amchart類軸上顯示時間戳,但在圖表中顯示爲undefined
。以下是圖表代碼:Amchart類軸中的時間戳顯示爲未定義
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"marginTop":0,
"marginRight": 80,
"dataProvider": [{
"date": 1492664639000,
"value": 10
}, {
"date": 1492664646000,
"value": 20
}, {
"date": 1492664653000,
"value": 20
}, {
"date": 1492664660000,
"value": 23
}, {
"date": 1492664667000,
"value": 35
}, {
"date": 1492664674000,
"value": 26
}, {
"date": 1492664681000,
"value": 30
}],
"valueAxes": [{
"axisAlpha": 0,
"position": "left"
}],
"graphs": [{
"id":"g1",
"balloonText": "[[category]]<br><b><span style='font-size:14px;'>[[value]]</span></b>",
"bullet": "round",
"bulletSize": 8,
"lineColor": "#d1655d",
"lineThickness": 2,
"negativeLineColor": "#637bb6",
"type": "smoothedLine",
"valueField": "value"
}],
"chartScrollbar": {
"graph":"g1",
"gridAlpha":0,
"color":"#888888",
"scrollbarHeight":55,
"backgroundAlpha":0,
"selectedBackgroundAlpha":0.1,
"selectedBackgroundColor":"#888888",
"graphFillAlpha":0,
"autoGridCount":true,
"selectedGraphFillAlpha":0,
"graphLineAlpha":0.2,
"graphLineColor":"#c2c2c2",
"selectedGraphLineColor":"#888888",
"selectedGraphLineAlpha":1
},
"chartCursor": {
"categoryBalloonDateFormat": "fff",
"cursorAlpha": 0,
"valueLineEnabled":true,
"valueLineBalloonEnabled":true,
"valueLineAlpha":0.5,
"fullWidth":true
},
"dataDateFormat": "YYYY-MM-DD HH:NN:SS",
"categoryField": "timestamp",
"categoryAxis": {
"minPeriod": "fff"
}
});
這是DEMO。
Thnks的作品。它在X軸上顯示時間戳。有沒有辦法在X軸上格式化時間戳? – iJade
您推薦給日期對象不是數字,並更改您需要的格式我認爲,這裏:https://codepen.io/anon/pen/gWPEoJ – Wei
您必須設置['parseDates'](http:// docs .amcharts.com/3/javascriptcharts/CategoryAxis#parseDates)在您的categoryAxis中設置爲true,以便圖表將您的時間戳解釋爲日期。這是一個更新的[demo](https://codepen.io/team/amcharts/pen/0c6177e5b1edfa5108bcf2f28b631598/)。 如果要進一步修改標籤,可以修改categoryAxis'['dateFormats'數組](http://docs.amcharts.com/3/javascriptcharts/CategoryAxis#dateFormats)。有一篇文章詳細介紹了這裏(https://www.amcharts.com/kbase/time-series-chart-the-great-advantages-of-parsing-dates/)。 – xorspark