1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| var padding = { width: 800, height: 800, }
var svg = d3.select('body') .append("svg") .attr("width",padding.width) .attr("height",padding.height)
var databases = [ { startAngle: 0, endAngle: Math.PI * 0.6 }, { startAngle: Math.PI * 0.6, endAngle: Math.PI }, { startAngle: Math.PI, endAngle: Math.PI * 1.7 }, { startAngle: Math.PI * 1.7, endAngle: Math.PI * 2} ]
var archPath = d3.svg.arc() .innerRadius(0) .outerRadius(200)
var color = d3.scale.category20b()
svg.selectAll("path") .data(databases) .enter() .append("path") .attr("d", function(d) { return archPath(d) }) .attr("transform", "translate(255,255)") .attr("stroke", "black") .attr("stroke-width", "1px") .attr("fill", function(d,i) { return color(i) })
svg.selectAll("text") .data(databases) .enter() .append("text") .attr("transform", function(d) { return "translate(255,255)" + "translate(" + archPath.centroid(d) + ")" }) .attr("text-anchor", "middle") .attr("fill","white") .attr("font-size","10px") .text(function(d) { return Math.floor((d.endAngle - d.startAngle) * 180 / Math.PI) + "°" })
|