Skip to content

Instantly share code, notes, and snippets.

@robballou
Created December 20, 2013 16:22
Show Gist options
  • Save robballou/8057245 to your computer and use it in GitHub Desktop.
Save robballou/8057245 to your computer and use it in GitHub Desktop.
Step 1: run our D3 script with node!
require('d3');
var xmldom = require('xmldom');
var dataset = {
apples: [53245, 28479, 19697, 24037, 40245],
};
var width = 460,
height = 300,
radius = Math.min(width, height) / 2;
var color = d3.scale.category20();
var pie = d3.layout.pie()
.sort(null);
var arc = d3.svg.arc()
.innerRadius(radius - 100)
.outerRadius(radius - 50);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var path = svg.selectAll("path")
.data(pie(dataset.apples))
.enter().append("path")
.attr("fill", function(d, i) { return color(i); })
.attr("d", arc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment