简体   繁体   中英

Example for animating a scatter plot in d3js

I have a set of about 1000 points that I'd like to scatter plot with d3js. I'd like about 10 points to appear every .1 seconds. Is there a simple example of this somewhere? The d3js tutorials are detailed, but I can't seem to find one for this case.

  • http://alignedleft.com/tutorials/d3/making-a-scatterplot/ and http://bl.ocks.org/bunkat/2595950 ->this example gives you a basic idea of how to draw a scatter plot!!!

  • http://swizec.com/blog/quick-scatterplot-tutorial-for-d3-js/swizec/5337 -->Tutorial

    You need to understand these first!!!

  • DEMO FIDDLE for your animation in scatterplot- --> http://jsfiddle.net/eaGhB/3/

      var w = 960,h = 500,nodes = []; var svg = d3.select("body").append("svg:svg") .attr("width", w) .attr("height", h); var force = d3.layout.force() .charge(-300) .size([w, h]) .nodes(nodes) .on("tick", tick) .start(); function tick() { svg.selectAll("circle") .attr("cx", function (d) { return dx; }) .attr("cy", function (d) { return dy; }); } var interval = setInterval(function () { var d = { x: w / 2 + 2 * Math.random()-1 , y: h / 2 + 2 * Math.random() - 1 }; svg.append("svg:circle") .data([d]) .attr("r", 10) .transition() .ease(Math.sqrt) .style("stroke", "gray") .style("fill", "red") .attr("r", 10); if (nodes.push(d) > 20) { clearInterval(interval); d3.selectAll('circle').on("mouseover", animate).on("mouseout", function () { d3.select(this).transition() .duration(100) .attr("r", 40); d3.selectAll('circle').style("fill", "black"); }); } force.stop() force.start(); }, 200); function animate() { d3.select(this).transition() .duration(300) .attr("r", 20); d3.select(this).style("fill", "green"); var sel = d3.select(this); sel.moveToFront(); }; d3.selection.prototype.moveToFront = function () { return this.each(function () { this.parentNode.appendChild(this); }); }; 

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