d3.js
需要你明确地方你吧坐标,所以,你可以把你的酒吧,在那里你永远喜欢:
// create a group for your overlapped bars
var g = svg.selectAll(".bars")
.data(data)
.enter().append("g")
// place the first bar
g.append("rect")
.attr("class", "bar1")
.attr("x", function(d) {
return x(d.letter) + 10; // center it
})
.attr("width", x.rangeBand() - 20) // make it slimmer
.attr("y", function(d) {
return y(d.col1);
})
.attr("height", function(d) {
return height - y(d.col1);
});
// place the second bar on top of it
g.append("rect")
.attr("class", "bar2")
.attr("x", function(d) {
return x(d.letter);
})
.attr("width", x.rangeBand())
.attr("y", function(d) {
return y(d.col2);
})
.attr("height", function(d) {
return height - y(d.col2);
});
这是一个快速example。
EDITS
要及时添加,你必须做出一些改变。
设置一个时间格式化,解析您的日期/时间你的文件:
// say date/times are local 20160622 15:00
var timeFormatter = d3.time.format("%Y%m%d %H:%M")
设置一个时间X-规模为您的轴:
// x scale showing 1 day - 06/22/2015
var x = d3.time.scale()
.range([0,width])
.domain([timeFormatter.parse("20150621 00:00"), timeFormatter.parse("20150622 00:00")])
当你画矩形,宽度是从endTime到startTime的像素数:
g.append("rect")
.attr("class", "bar1")
.attr("x", function(d) {
return x(d.startTime1); // start at startTime
})
.attr("width", function(d,i){
return x(d.endTime1) - x(d.startTime1); // pixel width from end to start
})
.attr("y", function(d) {
return y(d.col1);
})
.attr("height", function(d) {
return height - y(d.col1);
});
示例here。
完美地工作 - 谢谢!下一个和最后一个查询 - 图表上只有两列(一个灰色,一个蓝色)。我使用一个小节来表示时间段,例如上午8:10至下午15:00,其他酒吧时间09:45至15:00。我可以使每个栏的宽度反映时间段吗? – user3343633
不幸的是,我不能满足这个优秀的答案(没有足够的分数)。 – user3343633
@ user3343633,请参阅更新以回答。 – Mark