three little circle

2019-03-09  本文已影响0人  雷朝建
<svg style={{ width: 720, height: 120 }}>
  <circle cx="40" cy="60" r="10"></circle>
  <circle cx="80" cy="60" r="10"></circle>
  <circle cx="120" cy="60" r="10"></circle>
</svg>
1.png

选择元素

const circle = d3.selectAll('circle');
circle.style('fill', 'steelblue').attr('r', 30)
  .attr('cx', () => Math.random() * 720);

绑定数据

const data = [32, 57, 112];
const circle = d3.selectAll('circle');
circle.data(data).style('fill', 'steelblue').attr('r', (d, i) => i + Math.sqrt(d));
2.PNG

新建元素

const svg = d3.select("svg");
svg.selectAll("circle").data([32, 57, 112, 293])
  .enter().append("circle")
  .attrs({ cx: (d, i) => i * 100 + 30, cy: 60, r: d => Math.sqrt(d)});

删除元素

const svg = d3.select("svg");
svg.selectAll("circle").data([32, 57, 112, 293])
  .enter().append("circle")
  .attrs({ cx: (d, i) => i * 100 + 30, cy: 60, r: d => Math.sqrt(d)});

svg.selectAll("circle").data([32, 57])
  .exit().remove();
上一篇 下一篇

猜你喜欢

热点阅读