D3 折れ線グラフの x 軸をフォーマットしようとしていますが、値が完全に間違っています。データは、D3 経由で提供するために json に変換している Postgres データベースの「timestamp with timezone」列に由来します。
D3 スニペット
data.forEach(function(d) {
d.timestamp = new Date(d.timestamp*1000);
d.close=+d.close;
}
var timeFormat = d3.time.format("%d %b %y %X");
var x = d3.time.scale().range([ 0, width ]);
var xAxis = d3.svg.axis().scale(x).orient("bottom").tickFormat(timeFormat);
x.domain(d3.extent(data, function(d) {
return d.timestamp;
}));
Java から JSON への変換
ResultSet rs = st.executeQuery("select * from price_data order by timestamp);
...
String.format("{\"timestamp\":\"%d\",\"close\":\"%f\"}",rs.getTimestamp("timestamp").getTime(),rs.getDouble("price"));
値が 1426014732000 のタイムスタンプの軸フォーマットの結果
私が理解していないのは、javascriptをステップ実行してChromeのウォッチ式を介して呼び出すと、timeFormat関数が正常に機能することです...