0
var 데이터에서 원으로 텍스트를 추가하려면 어떻게해야합니까? 라벨에서 말한거야?d3.js에 텍스트 추가
내 코드 :
<!Doctype html>
<html>
<head>
<title>Dobble</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
</head>
<body>
<div id="canvas"></div>
<script type="text/javascript">
var w = 640,
h = 480;
var data = {
name : "root",
children : [
{ name: '1', size: 100, label: 'someText' },
{ name: '2', size: 85, label: 'someText' },
{ name: '3', size: 70, label: 'someText' },
{ name: '4', size: 55, label: 'someText' },
{ name: '5', size: 40, label: 'someText' },
{ name: '6', size: 25, label: 'someText' },
{ name: '7', size: 10, label: 'someText' },
]
}
var canvas = d3.select("#canvas")
.append("svg:svg")
.attr('width', w)
.attr('height', h);
var nodes = d3.layout.pack()
.value(function(d) { return d.size; })
.size([w, h])
.nodes(data);
nodes.shift();
canvas.selectAll('circles')
.data(nodes)
.enter().append('svg:circle')
.attr('cx', function(d) { return d.x; })
.attr('cy', function(d) { return d.y; })
.attr('r', function(d) { return d.r; })
.attr('fill', 'white')
.attr('stroke', 'grey');
</script>
</body>
</html>
기본적으로, 나는 텍스트가 중심에 있던 것을 걱정 : 그것은 방식처럼 계산에 기지/ – Shinzoo
당신이 원을 추가 | –
그럼이 예제에서 텍스트를 "가운데에 배치"할 수 있습니까? https://pastebin.com/HhLEvmq4 – Shinzoo