The difference from datum ()
Assuming that the array to bind is [3,6,9], then we want the first P element to bind 3, the second binding 6, and the third binding 9. This situation requires the use of the data () function, and if Datum () is used, the array itself is bound to each element, that is, the first P-element binding [3,6,9], the second binding [3,6,9], and the third binding [3,6,9].
Borrowing: http://www.ourd3js.com/wordpress/?p=797 's diagram
The data () function returns an object containing the update part and two functions. One is the Enter () function, which returns the Enter section, the Update property, and the exit () function, which returns to the Exit section.
The second parameter of data (): Key function
http://www.ourd3js.com/wordpress/?p=811, it's a very detailed story.
The order of the bindings does not bind by index number, but instead makes the key values correspond in turn. useful when updating data.
How to handle Enter
Scenario: More data, fewer elements.
Append () Adding elements
How to handle exit
Scenario: Less data, more elements.
Remove () Delete element
A set of processed templates: As a result, you can guarantee that one data corresponds to one element.
var dataset = [Ten, 30];var p = d3.select ("Body"). SelectAll ("P");//After binding data, return update, enter, exit part var update = P.data (da Taset); var enter = Update.enter (); var exit = Update.exit ();//1.update part processing Method Update.text (function (d) {return D;}); /2.enter part of the processing method Enter.append ("P"). Text (function (d) {return D;}); /3.exit part of the treatment Method Exit.remove ();
D3 data ()