我对使用非常大的数据集并尝试创建非常大的饼图数组的 D3 比较陌生。但是我不知道如何在每个饼图的最顶部放置标题。
我正在使用的数据目前是这样的 csv 格式,而水果将是我想要的饼图标签
[apple,90,36,2]
[pear,36,36,3]
[grape,19,13,0]
我在下面粘贴了我的代码,其中包含适用于它的数据。此外,我最终希望能够放大数据并从这样的缩小功能中查看它:
http://mbostock.github.io/d3/talk/20111116/pack-hierarchy.html
如果有人有有效传达这一点的想法,将不胜感激。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Multiple Pie Charts</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.4.5"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js?2.4.5"></script>
<style type="text/css">
body {
text-align: center;
}
</style>
</head>
<body>
<script type="text/javascript">
var data = [
[90,36,2],
[36,36,3],
[19,13,0],
]
var m = 10,
r = 100,
z = d3.scale.category20c();
var svg = d3.select("body").selectAll("svg")
.data(data)
.enter().append("svg:svg")
.attr("width", (r + m) * 2)
.attr("height", (r + m) * 2)
.append("svg:g")
.attr("transform", "translate(" + (r + m) + "," + (r + m) + ")");
svg.selectAll("path")
.data(d3.layout.pie())
.enter().append("svg:path")
.attr("d", d3.svg.arc()
.innerRadius(r / 2)
.outerRadius(r))
.style("fill", function(d, i) { return z(i); });
</script>
</body>
</html>