Showing posts with label d3. Show all posts
Showing posts with label d3. Show all posts

Friday, May 22, 2015

JavaScript D3 - random integer number

Decimal values are fine, but if you ever need whole numbers, you can use JavaScript’s Math.round() method. For example, you could wrap the random number generator from this line
    var newNumber = Math.random() * 30;
as follows:
    var newNumber = Math.round(Math.random() * 30);
Example:
d3.selectAll("p").style("color", function() { return "hsl(" + Math.round(Math.random() * 360) + ",100%,50%)"; });

JavaScript D3 - The power of data()

http://alignedleft.com/tutorials/d3/the-power-of-data

Wednesday, May 20, 2015

Javascript D3 good basic explanation

http://synthesis.sbecker.net/articles/2012/07/08/learning-d3-part-1

JavaScript D3 - example how the function(d, i) works

http://jsfiddle.net/M8nK8/

==HTML==
<script src="http://d3js.org/d3.v3.min.js"></script>
<section></section>


===JS D3==

var data=[10,20,30,40];

var lis = d3.select("section")
          .append("ul")
            .selectAll("li")
            .data(data)

lis.enter()
 .append("li")
 .text(function(d,i){ return "item n° "+i+" has value: "+d})

JavaScript D3 - forEach() vs each() function

The main takeaway is that, using .each() you get access to 3 things you need: dthis and i. With .forEach(), on an array (like in the example from the beginning) you only get 2 things (d and i), and you'd have to do a bunch of work to also associate an HTML element with those 2 things. And that, among other things, is how d3 is useful.

http://stackoverflow.com/questions/13465796/d3-javascript-difference-between-foreach-and-each