小编Ric*_*ard的帖子

d3.js - v3和v4 - 输入和更新差异

我正在尝试使用d3.js v4 获取值xy制作圆圈.使用以下代码,我设法创建图表,就像圈子的行为,但当我尝试在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: …
Run Code Online (Sandbox Code Playgroud)

html javascript version d3.js

3
推荐指数
1
解决办法
3279
查看次数

标签 统计

d3.js ×1

html ×1

javascript ×1

version ×1