我使用了一個非常簡單的nvd3線與焦點圖的例子。 myData
從我的php文件返回一個JSON對象,其中的x座標是0-23的數字。我想知道如何以小時格式格式化x軸。NVD3時間格式,與焦點圖線
d3.json('get_data.php', function (error, myData) {
// Renders a line chart
(function() {
nv.addGraph(function() {
var chart = nv.models.lineWithFocusChart();
chart.xAxis
.tickFormat(d3.format(''));
chart.yAxis
.tickFormat(d3.format(''));
chart.y2Axis
.tickFormat(d3.format(''));
d3.select("#chart svg")
.datum(myData)
.transition().duration(500)
.call(chart); //Define transition and pass the d3.selection to our lineChart.
nv.utils.windowResize(chart.update);
return chart; //Must return the enclosed chart variable so the global rendering queue can store it.
//});
});
})(); });
這裏是myData
樣品JSON數據。無論如何我需要操縱它嗎?
[{ "key": "data", "values": [ { "x": 0, "y": 408175 }, { "x": 1, "y": 428739 }, { "x": 2, "y": 422141 }, { "x": 3, "y": 439864 }, { "x": 4, "y": 441409 } ] }]
任何幫助表示讚賞。
如果你正在使用moment.js,你可以不喜歡'chart.xAxis.tickFormat(函數(d){VAR 時間=時刻()。小時(d)。分鐘(0)._ d; return d3.time.format('%H:%M%p')(time); });' –