私のデータは d [ Object, Object,.... ] の形式で、各オブジェクトは {count:5 time:1352961975 } の形式で、time は Unix タイムスタンプです。カウント値に対して時間に基づいてこれをプロットしたいと思います。カウント値は y 軸にプロットされ、時間は 12:30 AM 、1 AM、1:30 AM ... として x 軸にプロットされます。現在時刻へ。
このような
var midnight_time = new Date();
midnight_time.setHours(0,0,0,0);
x = d3.time.scale()
.range([0,width])
.domain([ new Date(midnight_time),new Date()]);
y = d3.scale.linear()
.domain([0,ymax]) //by using ajax not shown here getting the value of ymax
.range([height, 0]);
line = d3.svg.line()
.x(function(d) { return x(d.count); })
.y(function(d) { return y(d.time); });
svg = d3.select("#viz").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.append("defs").append("clipPath")
.attr("id", "clip")
.append("rect")
.attr("width", width)
.attr("height", height);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(d3.svg.axis().scale(x).orient("bottom")
.ticks(d3.time.minutes,tick_count));
svg.append("g")
.attr("class", "y axis")
.call(d3.svg.axis().scale(y).orient("left"));
d3.select(".x.axis")
.append("text")
.text("the time span")
.attr("transform", "translate(360,30)");
d3.select(".y.axis")
.append("text")
.text("Maximum number of active users")
.attr("transform", "rotate (-90, -35, 0) translate(-210)");
path = svg.append("g")
.attr("clip-path", "url(#clip)")
.append("path")
.data([data])
.attr("class", "line")
.attr("d", line);
時間のフォーマットを正しく適用していないと思います。Unix タイムスタンプを AM または PM 形式の正しい時刻に変換し、それに応じてグラフ プロットを呼び出す必要があります。