Chr*_*che 36 javascript transition real-time d3.js nvd3.js
我正在尝试使用nvd3.js创建一个实时图表,它会定期更新,并且会产生实时处理数据的印象.
现在我已经能够创建一个定期更新图形的函数,但我无法在"状态"之间进行平滑过渡,例如向左转换的行.
这是我使用nvd3.js所做的,这里有趣的代码是:
d3.select('#chart svg')
.datum(data)
.transition().duration(duration)
.call(chart);
Run Code Online (Sandbox Code Playgroud)
现在,我已经能够使用d3.js生成我想要的东西,但我希望能够使用nvd3.js提供的所有工具.这是我想用nvd3制作的
使用d3.js进行转换的有趣代码是:
function tick() {
// update the domains
now = new Date();
x.domain([now - (n - 2) * duration, now - duration]);
y.domain([0, d3.max(data)]);
// push the accumulated count onto the back, and reset the count
data.push(Math.random()*10);
count = 0;
// redraw the line
svg.select(".line")
.attr("d", line)
.attr("transform", null);
// slide the x-axis left
axis.transition()
.duration(duration)
.ease("linear")
.call(x.axis);
// slide the line left
path.transition()
.duration(duration)
.ease("linear")
.attr("transform", "translate(" + x(now - (n - 1) * duration) + ")")
.each("end", tick);
// pop the old data point off the front
data.shift();
}
Run Code Online (Sandbox Code Playgroud)
Ale*_*par 13
你可能想看看: D3 Real-Time streamgraph(图形数据可视化),
特别是答案的链接:http: //bost.ocks.org/mike/path/
总的来说,我看到了两种处理垂直过渡问题的方法:
| 归档时间: |
|
| 查看次数: |
16043 次 |
| 最近记录: |