簡體   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