2017-06-21 85 views
1

我想創建一個具有倍數日期值的圖表,但它不工作。我認爲邏輯很好,而且amChart不喜歡這種日期格式。有任何想法嗎 ?AmChart的倍數日期值

工作爲例:

var chart = AmCharts.makeChart("chartdiv", { 
    type: "xy", 
    dataProvider: [ { 
    "ax": 16.10, <-------- 
    "ay": 2, 
    "bx": 16.11, <-------- 
    "by": 2 
    }, { 
    "ax": 16.20, <-------- 
    "ay": 3, 
    "bx": 16.21, <-------- 
    "by": 3 
    }], 
    graphs: [ { 
    "xField": "ax", 
    "yField": "ay" 
    }, { 
    "xField": "bx", 
    "yField": "by" 
    } ], 
}); 

我試圖讓:

var chart = AmCharts.makeChart("chartdiv", { 
    type: "xy", 
    dataProvider: [ { 
    "ax": "2017/04/27 09:16:10", <-------- 
    "ay": 2, 
    "bx": "2017/04/27 09:16:11", <-------- 
    "by": 2 
    }, { 
    "ax": "2017/04/27 09:16:20", <-------- 
    "ay": 3, 
    "bx": "2017/04/27 09:16:21", <-------- 
    "by": 3 
    }], 
    graphs: [ { 
    "xField": "ax", 
    "yField": "ay" 
    }, { 
    "xField": "bx", 
    "yField": "by" 
    } ], 
}); 

http://jsfiddle.net/Lktv4s4b/1/

回答

0

基於日期的數據,你必須爲你的圖表指定dataDateFormat讓AmCharts知道如何正確解析你的日期。由於您使用的是XY圖表,因此您還必須告訴AmCharts您有一個基於日期的數值軸(XY圖表只有數值軸,與串行圖不同),您必須指定哪一個是基於日期的。通過你的數據去,你的X軸是基於日期的,所以你至少需要告訴它的底部值軸type"date"

AmCharts.makeChart("chartdiv", { 
    type: "xy", 
    dataDateFormat: "YYYY/MM/DD JJ:NN:SS", 
    valueAxes: [{ 
    position: "bottom", 
    type: "date" 
    }], //you can also specify the second value axis' properties if needed, but it will create a numeric y-axis for you by default if you don't 
    // ... rest of your properties omitted ... 
}); 

更新小提琴:http://jsfiddle.net/Lktv4s4b/2/

+1

它的工作完美,感謝很多 ! 我試過dataDateFormat,但我一定忘了valueAxes.type! 乾杯! –