سؤال

لدي تريماب وضعت مع D3.js.أضع البيانات عبر GetJson.انها تعمل كبيرة.ومع ذلك، لدي هذه الوظيفة في طريقة SetInterval ولا يبدو أنها منعشة نفسها. giveacodicetagpre.

سؤالي على وجه التحديد، ولهذا السبب عندما أغير البيانات في ملف JSON لا تظهر بعد 3 ثوان في وقت لاحق في تريل؟

شكرا لك مقدما.

هل كانت مفيدة؟

المحلول

What's in the data? Because if the data array has the same length, the enter() selection (which corresponds to previously unbound data) will have a length of zero. Mike Bostock wrote a great tutorial called Thinking with Joins, which I would recommend reading before you go any further.

The svg.data() call seems redundant, and for clarity's sake I'd recommend doing this instead:

var leaves = treemap(json);
console.log("leaves:", leaves); // so you can see what's happening

// cell here is the bound selection, which has 3 parts
var cell = svg.selectAll("g")
  .data(leaves);
// you might want to console.log(cell) here too so you can take a look

// 1. the entering selection is new stuff
var entering = cell.enter()
  .append("g")
entering.append("rect")
  // [update rectangles]
entering.append("text")
  // [update text]

// 2. the exiting selection is old stuff
cell.exit().remove();

// 3. everything else is the "updating" selection
cell.select("rect")
  // [update rectangles]
cell.select("text")
  // [update text]

You can also encapsulate the updating of cells in a function and "call" it on both the entering and updating selections, so you don't have to write the same code twice:

function update() {
  cell.select("rect")
    // [update rectangles]
  cell.select("text")
    // [update text]
}

entering.append("rect");
entering.append("text");
entering.call(update);

cell.call(update);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top