-
-
Save btipling/4370820 to your computer and use it in GitHub Desktop.
Revisions
-
enjalot revised this gist
Sep 15, 2011 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ <!DOCTYPE html> <html> <head> -
enjalot revised this gist
Sep 15, 2011 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ <!-- Annotated javascript available at http://enja.org/code/tuts/d3/bar --> <!-- Code walkthrough screencast available at --> <!DOCTYPE html> <html> <head> -
enjalot revised this gist
Sep 15, 2011 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,9 +3,9 @@ <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <title>Testing Pie Chart</title> <script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.1.3"></script> <script type="text/javascript" src="http://mbostock.github.com/d3/d3.geom.js?2.1.3"></script> <script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js?2.1.3"></script> <style type="text/css"> .slice text { -
enjalot revised this gist
Sep 8, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,9 +40,9 @@ var pie = d3.layout.pie() //this will create arc data for us given a list of values .value(function(d) { return d.value; }); //we must tell it out to access the value of each element in our data array var arcs = vis.selectAll("g.slice") //this selects all <g> elements with class slice (there aren't any yet) .data(pie) //associate the generated pie data (an array of arcs, each having startAngle, endAngle and value properties) .enter() //this will create <g> elements for every "extra" data element that should be associated with a selection. The result is creating a <g> for every object in the data array .append("svg:g") //create a group to hold each slice (we will have a <path> and a <text> element associated with each slice) .attr("class", "slice"); //allow us to style things in the slices (like text) -
enjalot revised this gist
Sep 8, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ <style type="text/css"> .slice text { font-size: 16pt; font-family: Arial; } </style> -
enjalot revised this gist
Sep 8, 2011 . 1 changed file with 29 additions and 27 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,55 +8,57 @@ <script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js?1.29.1"></script> <style type="text/css"> .slice text { font-size: 20pt; font-family: Arial; } </style> </head> <body> <script type="text/javascript"> var w = 300, //width h = 300, //height r = 100, //radius color = d3.scale.category20c(); //builtin range of colors data = [{"label":"one", "value":20}, {"label":"two", "value":50}, {"label":"three", "value":30}]; var vis = d3.select("body") .append("svg:svg") //create the SVG element inside the <body> .data([data]) //associate our data with the document .attr("width", w) //set the width and height of our visualization (these will be attributes of the <svg> tag .attr("height", h) .append("svg:g") //make a group to hold our pie chart .attr("transform", "translate(" + r + "," + r + ")") //move the center of the pie chart from 0, 0 to radius, radius var arc = d3.svg.arc() //this will create <path> elements for us using arc data .outerRadius(r); var pie = d3.layout.pie() //this will create arc data for us given a list of values .value(function(d) { return d.value; }); //we must tell it out to access the value of each element in our data array var arcs = vis.selectAll("g.slice") // .data(pie) //associate the generated pie data (an array of arcs, each having startAngle, endAngle and value properties) .enter() // .append("svg:g") //create a group to hold each slice (we will have a <path> and a <text> element associated with each slice) .attr("class", "slice"); //allow us to style things in the slices (like text) arcs.append("svg:path") .attr("fill", function(d, i) { return color(i); } ) //set the color for each slice to be chosen from the color function defined above .attr("d", arc); //this creates the actual SVG path using the associated data (pie) with the arc drawing function arcs.append("svg:text") //add a label to each slice .attr("transform", function(d) { //set the label's origin to the center of the arc //we have to make sure to set these before calling arc.centroid d.innerRadius = 0; d.outerRadius = r; return "translate(" + arc.centroid(d) + ")"; //this gives us a pair of coordinates like [50, 50] }) .attr("text-anchor", "middle") //center the text on it's origin .text(function(d, i) { return data[i].label; }); //get the label from our original data array </script> </body> -
enjalot revised this gist
Sep 8, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,8 +17,8 @@ <body> <script type="text/javascript"> var w = 300, h = 300, r = 100, color = d3.scale.category20c(); -
enjalot revised this gist
Sep 8, 2011 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,7 +36,7 @@ .outerRadius(r); var pie = d3.layout.pie() .value(function(d) { return d.value; }); var arcs = vis.selectAll("g.slice") .data(pie) @@ -49,12 +49,11 @@ .attr("d", arc); arcs.append("svg:text") .attr("transform", function(d) { //we have to make sure to set these before calling arc.centroid d.innerRadius = 0; d.outerRadius = r; return "translate(" + arc.centroid(d) + ")"; }) .attr("text-anchor", "middle") .text(function(d, i) { return data[i].label; }); -
enjalot created this gist
Sep 8, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <title>Testing Pie Chart</title> <script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?1.29.1"></script> <script type="text/javascript" src="http://mbostock.github.com/d3/d3.geom.js?1.29.1"></script> <script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js?1.29.1"></script> <style type="text/css"> text { font-size: 12pt; font-family: Arial; } </style> </head> <body> <script type="text/javascript"> var w = 640, h = 480, r = 100, color = d3.scale.category20c(); data = [{"label":"one", "value":20}, {"label":"two", "value":50}, {"label":"three", "value":30}] var vis = d3.select("body") .append("svg:svg") .data([data]) .attr("width", w) .attr("height", h) .append("svg:g") .attr("transform", "translate(" + r + "," + r + ")") var arc = d3.svg.arc() .outerRadius(r); var pie = d3.layout.pie() .value(function(d) { return d.value; }) var arcs = vis.selectAll("g.slice") .data(pie) .enter() .append("svg:g") .attr("class", "slice"); arcs.append("svg:path") .attr("fill", function(d, i) { return color(i); } ) .attr("d", arc); arcs.append("svg:text") .attr("transform", function(d, i) { console.log(d); //we have to make sure to set these before calling arc.centroid d.innerRadius = 0; d.outerRadius = r; return "translate(" + arc.centroid(d) + ")"; }) }) .attr("text-anchor", "middle") .text(function(d, i) { return data[i].label; }); </script> </body> </html>