D3.JS--02 (Data and Datum principles)

Source: Internet
Author: User

Original link:

Http://d3.decembercafe.org/pages/lessons/3.html

Parse the data and datum principle:

    • Datum (): Binds a data to a selection set
    • Data (): Binds an array to the selection set, and the values of the array are bound to each element of the selection set, respectively
<! DOCTYPE html>
<meta charset= "UTF-8" >
<meta name= "viewport" content= "Width=device-width, initial-scale=1.0" >
<meta http-equiv= "x-ua-compatible" content= "Ie=edge" >
<title> Data Binding </title>
<script src= "D3.js" ></script>
<body>

<p>apple</p>
<p>organge</p>
<p>banaer</p>
<span></span>
<span></span>
<span></span>


<script>
Datum ()
var str = ' CCZ ';
var BODY = d3.select (' body ');
var p = body.selectall (' P ');
P.datum (str);
Console.log (P);

P.text (function (d,i) {
Return ' +i+ ' binding element is ' +d;
})
Data ()
var obj = [' like1 ', ' like2 '];
var span = Body.selectall (' span ');
Span.data (obj);
Console.log (span);
P.text (function (d,i) {
return D;
})



</script>
</body>

When printing, it is found that the attributes of each P element will be one more __data__, and the corresponding data will be bound on this property.

Datum () binds the value to the __data__ attribute, and the values of all elements are the same;

Data () assigns the array object to the element, and if the value is not sufficient, the text of the element is empty.

D3.JS--02 (Data and Datum principles)

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.