0
我試圖解決這一問題水汪汪的條形圖以便它能夠處理動態數據集 - http://jsfiddle.net/NYEaX/1855/
有一個問題與唱片公司的定位和調整線的寬度/高度。
var lineHeights = 100;
//__ labels
var labels = labelsholder.selectAll("text")
.data(data);
labels.enter()
.append("text")
.attr("class", "barlabels")
.attr("x", 200)
.attr("y", function(d, i) {
return lineHeights - (20 * i);
})
.text(function(d) {
return d.label;
})
var lines = lineholder.selectAll("line")
.data(data);
//horizontal
lines.enter()
.append("line") // attach a line
.style("stroke-dasharray", ("3, 3"))
.style("stroke", "black") // colour the line
.attr("x1", function(d, i) {
return barWidth - 100/(i+1);
}) //x pos of the 1st end of the line
.attr("y1", function(d, i) {
return lineHeights - (20 * i);
}) //y pos of the 1st end of the line
.attr("x2", function(d, i) {
return barWidth;
}) //x pos of the 2nd end of the line
.attr("y2", function(d, i) {
return lineHeights - (20 * i);
}); //y pos of the 2nd end of the line
//verticals
lines.enter()
.append("line") // attach a line
.style("stroke-dasharray", ("3, 3"))
.style("stroke", "black") // colour the line
.attr("x1", function(d, i) {
return 30 * i;
}) //x pos of the 1st end of the line
.attr("y1", function(d, i) {
return lineHeights - (20 * i);
}) //y pos of the 1st end of the line
.attr("x2", function(d, i) {
return 30 * i;
}) //x pos of the 2nd end of the line
.attr("y2", function(d, i) {
return -15;
}); //y pos of the 2nd end of the line
這看起來不錯 - 我已經刪除了關於反轉數據的評論 - http://jsfiddle.net/NYEaX/1861/ - 有沒有可以在這個圖表上做出其他改進? –
你的其他改進意味着什麼? (代碼幾乎總是可以改進的)。 – Lissy
我的意思是你看到這個代碼庫的任何增強 - 使代碼更緊 - @Lissy –