首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有nvd3.js的实时线图

带有nvd3.js的实时线图
EN

Stack Overflow用户
提问于 2013-03-11 02:45:02
回答 1查看 16.6K关注 0票数 36

我正在尝试使用nvd3.js创建一个实时图,它将定期更新,并且给人的印象是数据是实时处理的。

目前,我已经能够创建一个函数来定期更新图形,但我无法在“状态”之间进行平稳的转换,比如向左转换的直线。

Here是我使用nvd3.js所做的,这里的有趣代码是:

代码语言:javascript
复制
d3.select('#chart svg')
    .datum(data)
    .transition().duration(duration)
    .call(chart);

现在,我已经能够使用d3.js生成我想要的东西,但我更希望能够使用nvd3.js提供的所有工具。Here是我想用nvd3制作的产品

使用d3.js进行转换的有趣代码是:

代码语言:javascript
复制
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();

}
EN

回答 1

Stack Overflow用户

发布于 2013-05-16 23:18:44

你可能想看看:D3 Real-Time streamgraph (Graph Data Visualization)

特别是答案的链接:http://bost.ocks.org/mike/path/

总的来说,我看到了处理垂直过渡问题的两种方法:

  • 过采样在实际点之间有一些线性插值,而且点间间隔越小,垂直过渡看起来越“水平”(但缺点是你得到了大量的“假”点,这取决于图表的使用情况。)
  • 通过在末尾添加图表来扩展图表,并在左边转换图表,确保在删除它之前不会显示仍然可用的左侧部分(剪裁它或执行任何其他技巧),这是最好的,上面提到的解决方案就是这样做的。
票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15330390

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档