public
Created

starting point for my labels...

  • Download Gist
index.html
HTML
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 57 58 59 60 61 62
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v2.js"></script>
<script type="text/javascript" src="https://raw.github.com/ZJONSSON/d3-plugins/master/force_labels/force_labels.js"></script>
<style>
.anchor { fill:blue}
.labelbox { fill:black;opacity:0.8}
.labeltext { fill:white;font-weight:bold;text-anchor:middle;font-size:16;font-family: serif}
.link { stroke:gray;stroke-width:0.35}
</style>
</head>
 
<body>
<div id="div1"></div>
 
<script type="text/javascript">
var w=960,h=500,
x_mean = w/2,
x_std = w/10,
y_mean = h/2,
y_std = h/10,
labelBox,link;
var width = 400,
height = 400,
outerRadius = Math.min(width, height) / 2,
innerRadius = outerRadius * .6,
data = d3.range(10).map(Math.random),
color = d3.scale.category20(),
donut = d3.layout.pie(),
arc = d3.svg.arc().innerRadius(innerRadius).outerRadius(outerRadius);
var myData = [{text: "hello", size: 2},{text: "hello2", size: 27},{text: "hello3", size: 7},{text: "hello4", size: 2},{text: "hello5", size: 1},{text: "hello6", size: 1}]
 
var vis = d3.select("#div1")
.append("svg")
.data([myData])
.attr("width", width)
.attr("height", height);
var arcs = vis.selectAll("g.arc")
.data(donut.value(function(d) { return d.size; }))
.enter().append("g")
.attr("class", "arc")
.attr("transform", "translate(" + outerRadius + "," + outerRadius + ")");
arcs.append("path")
.attr("fill", function(d, i) { return color(i); })
.attr("d", arc);
var div_1019 = arcs.append("rect")
.attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; })
.attr("dy", ".35em");
div_1019.append("text")
.attr("text-anchor", "middle")
.text(function(d, i) { return myData[i].text == "" ? "no response" : myData[i].text });
div_1019.append("text")
.attr("text-anchor", "middle")
.text(function(d, i) { return d.value.toFixed(0) });
</script>
</body>
</html>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.