D3 data ()

Source: Internet
Author: User

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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.