In D3.js, there are two functions for selecting an element: Select and SelectAll. Let's start by explaining their differences:
Select is the first selection of all specified elements
SelectAll is the selection of all of the specified elements (for later simultaneous operation)
To see a specific example, the following code is available:[HTML]View PlainCopy
html>
head>
meta charse
China), just:[HTML]View PlainCopy
Sp.text ("China");
Can. If you want to use the set to assign a value, to use function functions (d,i), the function of the first parameter means datum (data), the second argument is index (index), it is important to note that when data function data is specified The set of data set and the P set you selected are one by one corresponding (if the number of sets and p is exactly the same, the case will be discussed later). The function has only one
Now let's start with d3.js to deal with the first simple question, and look at the following code:[html]View PlainCopy
html>
head>
meta charset="utf-8">
title>helloworldtitle>
head>
body>
P>hello World 1P>
p>hello World 2P>
Body>
html>
If you have studied html, you should know that two lines of text will be printed on the screen, such as:What if you want t
two numbers, but the number must be equal, as shown in the case of 3 numbers:var scale = d3.scale.linear (); Scale.domain ([0,20,40]). Range ([0,100,150]); var result = scale (30);This indicates that there are two linear functions when the output In the value of 30 o'clock, which belongs to the domain (definition field) of the 20–40 range, then the output is 100–150 this range. Here 30 corresponds to a value of 125, so the value of result is 125.
The first test of the successful D3.js code needs to be opened in the IE9 and above browsers. Firefox and Google can also try. Delete "20"rows="8"id="con">"运行代码"type="button"id="btn"/>Test the successful D3.js code
p.data (persons, function (d) {return d.id;}). Text (function (d) {return d.id + ":" + D.name;});There is only one statement return d.id in the key function. Represents a key using the ID property of an array item. After modifying the contents of the P element with the data of this binding, the result is as follows:As you can see, the results are not arranged in the order of the New Persons Array (6: Zhang San, 9: John Doe, 3: Harry). As shown in binding procedure 1, the order of the bindings d
simplified version of GeoJSON, which can be said to be a GeoJSON child. The author of D3.js thinks GeoJSON is not very good, and it is more admired Topojson format.Topojson compared to GeoJSON, the file size is reduced by 80% because:
The boundary line is recorded only once (for example, the junction lines in Guangxi and Guangdong province are recorded only once)
Do not use floating-point numb
want to select the third There are two ways:(1) Assign an ID to the third id= "P3">Hello World 3p>Then choosevar sp = d3.select ("#p3"); // Select ElementYou can do it again.(2) If data is bound, it can be manipulated in function (D,i), for exampleSp.text (function(d,i) { if(i==2) { ... } // if i = = 0 and I = = 1 are not specified, the null value will be returned automatically });However, it is important to note that, in thi
use it this way:var link = svg.selectall (". Link"). data (links). enter (). Append ("path") . attr ("Class", "link") . attr ("D", diagonal);This draws the lines between all the nodes. Next we'll draw the node.Nodes are also drawn using the circle in SVG. This is no longer the case. I've already talked about it before. You can also view the source code yourself. The result diagram is:If you want to view the source code, please click on the following URL. Right-click the
("X2", function (d) {return d.target.x;}) . attr ("Y2", function (d) {return d.target.y;}); Node.attr ("Transform", function (d) { return "translate (" + D.x + "," + D.y + ")"; } ";});Here as in section 9.2, tick refers to the time interval, that is, every time interval after the refresh of the picture, the content of the refresh is written in the nameless function functions, the function is written in the contents of the drawing. Here you see, 第7-9 is used for panning, and the
setting the action distance of the gravitational force, exceeding this distance, there is no gravitational force. The default value is infinity.Gravity ()The center of the size function creates gravity, and each vertex moves toward the center, with a default value of 0.1. It can also be set to 0, without the effect of gravity.Theta ()If the number of vertices is too large, the calculation time will be increased (O (n log n)). The theta is meant to limit this calculation, and the default value i
D3.js is also a JavaScript framework, like jquery, except that his specialty is in the data visualization of this piece. So don't think the D3 is so complicated. In the above code we can see some of the uses of D3:Select element:d3.select ("element"), this is the $ () in jquery, but not in shorthand form.After creating
D3.js Data Visualization Practical Manual study notesThe interpolator interpolation a given range of values and prints it in the middle.Character interpolation
var data=[];var sizescale=d3.scale.linear (). Domain ([0,9]). Range (["Italic bold 12px/30px Georgia, serif", "Italic bold 120px/180px Georgia, serif "]); for (Var i=0;iColor interpolation
var
d.target.x;}); Edges_line.attr ("Y2", function (d) {return d.target.y;}); Update the position of text on the connector edges_text.attr ("X", function (d) {return (d.source.x + d.target.x)/2;}); Edges_text.attr ("Y", function (d) {return (d.source.y + d.target.y)/2;}); Whether to draw the text on the connector Edges_text.style ("Fill-opacity", function (d) {return D.source.show | | d.target.show 1:0.0;}); Update the node image and text nodes_img.attr ("X", function (d) {return D.X-IMG_W/2;});
= 20;var Nodes_text = Svg.selectall (". Nodetext"). Data (Root.nodes). Enter ( ). Append ("text"). attr ("Class", "Nodetext"). attr ("DX", TEXT_DX). attr ("dy", Text_dy). Text (function (d) {return d.name;});第1-16 Line: Drawing a picture第10-15: Displays the text on the connector you want to associate with this node when you move the mouse over the picture. This is just a Boolean assignment for D.show, which is used later in the update.第21-30: Draw text below the picture4.5 UpdateTo keep the mec
Website:
http://d3js.org/Example:
Https://github.com/mbostock/d3/wiki/GalleryReference:
Online reference //or download to local Begin:
D3.select implementing a single element selectionSelect.attr, reading/Setting element properties
select.classed, adding/removing element classes
Remove the P1 class for P tags D3.
slowly reaches the last state of the transformation
Elastic with bouncing reach finally state
Bounce bouncing a few times at the last state.
Called when the shape is:. Ease ("bounce")4.delay ()Specifies the time of the delay, which indicates a certain amount of time before the transition is initiated and the unit is the same in milliseconds. This function can specify a delay for the population. You can also specify a delay for an individual.For general designations, such as:. Trans
The advanced series of tutorials has been completed and is hereby summarized.At the beginning of the month, I said the end of the advanced tutorial, today is the last day, can be done. O (∩_∩) o~As a result, the tutorials for the "Getting Started"-"advanced"-"premium" three series are complete. The purpose of this tutorial is to provide a network of free learning series, I hope you can enjoy.In the process of writing the article, the author's understanding of
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.