繁体   English   中英

在d3js中为散点图设置动画的示例

[英]Example for animating a scatter plot in d3js

我想用d3js散布约1000个点。 我希望每0.1秒显示10点。 在某个地方有一个简单的例子吗? d3js教程很详细,但我似乎找不到适合这种情况的教程。

  • http://alignedleft.com/tutorials/d3/making-a-scatterplot/http://bl.ocks.org/bunkat/2595950- >本示例为您提供了如何绘制散点图的基本思想! !

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

    您需要首先了解这些!!!

  • 在散点图中为动画制作演示场 --> 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); }); }; 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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