【发布时间】:2018-04-12 10:11:08
【问题描述】:
我正在尝试获取 x 和 y 的值以使用 d3.js v4 创建一个圆圈。使用以下代码,我设法创建了类似于圆圈行为的图表,但是当我尝试在 v4 中运行相同的代码时,它不再起作用了。我知道 v4 的更新存在一些差异,但我没有找到任何有关它的信息。所以我想知道是否有人可以帮助我在 d3.js v4 中运行这段代码。
这是使用 v3 的代码(使用 v4 会中断):
var svg = d3.select('body').append('svg')
.attr('width', 250)
.attr('height', 250);
//render the data
function render(data) {
//Bind
var circles = svg.selectAll('circle').data(data);
//Enter
circles.enter().append('circle')
.attr('r', 10);
//Update
circles
.attr('cx', function(d) {
return d.x;
})
.attr('cy', function(d) {
return d.y;
});
//Exit
circles.exit().remove();
}
var myObjects = [{
x: 100,
y: 100
}, {
x: 130,
y: 120
}, {
x: 80,
y: 180
}, {
x: 180,
y: 80
}, {
x: 180,
y: 40
}];
render(myObjects);
<script src='https://d3js.org/d3.v3.min.js'></script>
【问题讨论】:
标签: javascript html d3.js version