简体   繁体   中英

D3 transition not working

I have the following SVG element:

<svg id='svgTest' xmlns="http://www.w3.org/2000/svg" version="1.1">
  <g id="test">
    <rect height="20" width="50" fill="blue"/>
  </g>
</svg>

I want to add a transition for the blue rectangle. I tried with the following code with D3:

var rect = d3.select("#test");
rect.transition().duration(5000).attr('height',200);

But it doesn't seem to do anything. What's wrong?

You need to select the 'rect' element. Try this:

var rect = d3.select("#test rect");

rect.transition().duration(5000).attr('height',200);

If you want to update multiple elements, use d3.selectAll().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM