我正在學習創建D3js可重用模塊,其中包括Mike的Towards Reusable Charts article,Christophe Viau的The D3 Reusable API Speech(分鐘10到20)和a fiddle,我在Stackoverflow上找到了它。我簡化了可重複使用的模塊,預計生產4×2米的長方形,但目前只生產了2先失敗,則循環正常在我的其他數據:D3js最小可重複使用模塊不循環?
//Data
var data = [
{row: 0, col: 0, value: [{x: 1, y: 19}, {x: 2, y: 20}]}, // <= This only is produced!
{row: 0, col: 1, value: [{x: 1, y: 24}, {x: 2, y: 27}]}, // <= from there it fails
{row: 1, col: 1, value: [{x: 1, y: 31}, {x: 2, y: 26}]},
{row: 1, col: 2, value: [{x: 1, y: 29}, {x: 2, y: 19}]}
];
JS這應該循環在我的數據:
function exports(_selection) { // create function to export
_selection.each(function(_data) { // loop
var test_data = _data.value;
var rectW = (_data.row+2)*10,
rectH = (_data.col+1)*10;
// Select all bars and bind data:
var bars = svg.selectAll(".bar")
.data(test_data)
.enter().append("rect");
console.log(i+": "+JSON.stringify(_data.value));
// design svg elements
bars.attr("class","bar")
.attr({
'width': rectH,
'x': function (d){ console.log(" log place1! "); return d.x * 10;},
'y': function (d){ return d.y * 4;},
'height': rectH*4});
console.log(" log place2! ");
});
}// exports end
如何讓它循環?fiddle。
感謝meetamit,我沒看出來。工作中 ! – Hugolpz 2014-08-28 07:06:43