var width = 400, height = 400, radius = Math.min(width, height) / 2; var hist = window.histograms.states; var total = d3.sum(hist,function(d) { return d.hits }); var desc = d3.select('#desc'); desc.text('Total: '+total); var color = d3.scale.ordinal() .range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]); var arc = d3.svg.arc() .outerRadius(radius) .innerRadius(radius / 4); var pie = d3.layout.pie() .sort(null) .value(function(d) { return d.hits; }); var svg = d3.select("#chart-div").append("svg") .attr("width", width) .attr("height", height) .append("g") .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); var g = svg.selectAll(".arc") .data(pie(hist)) .enter().append("g") .attr("class", "arc"); g.append("path") .attr("d", arc) .style("fill", function(d) { return color(d.data.hits); }) .on("mouseover",function(d) {desc.text(d.data.name+': '+d.data.hits);}) .on("mouseout",function(d) {desc.text('Total: '+total);}); g.append("text") .attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; }) .attr("dy", ".35em") .style("text-anchor", "middle") .text(function(d) {return d.data.name});