Tuesday, 8 April 2014

Writing text in d3 and Alerts

There are, of course, a variety of ways to do this.

One way from http://thecodingtutorials.blogspot.co.uk/2012/07/introduction-to-d3.html:


is this

 var test = d3.select("body").data([1, 2, 3]);
  
        test.enter().append("p").append("test").text(function(d)
 {
  return "Hey there... #" + d;
 });



Another way from http://chimera.labs.oreilly.com/books/1230000000345/ch05.html#_beyond_text

is this
script type="text/javascript">

var dataset = [5, 10, 15, 20, 25 ];

d3.select("body").selectAll("p")
.data(dataset)
.enter()
.append("p")
.text(function(d) { 
return "I can count to " +(d*10); 
})
.style("color", function(d) {
    if (d > 15) {   //Threshold of 15
       return "red";
   } else {
       return "black";
    }
});

I am trying to get this to write my array on the web page and it works.

Just learned this interesting thing:
alert(data)
will put the data in a javascript dialog box.
Great!!!


No comments:

Post a Comment