简体   繁体   English

D3.js扫描图

[英]D3.js Sweep Graph

I am building a dynamic line graph with d3.js that shows a fixed period of time and associated data values (high data resolution), and is constantly updated with the latest data sets. 我正在使用d3.js构建动态折线图,它显示固定的时间段和关联的数据值(高数据分辨率),并使用最新数据集进行不断更新。

There are lots of examples that use a push/pop and translate mechanism to get a line that scrolls across the viewable area. 有很多示例使用推/弹出和转换机制来获得在可见区域中滚动的一行。

Rather than scrolling the graph, I would like the graph to remain fixed and instead, scroll the 'pen'. 与其滚动图表,不如使图表保持固定,而是滚动“ pen”。 The effect would be much like the unrolling line example found here 效果非常像此处找到的展开示例

When my line gets to the end of the viewable area, I would like to wrap back to the start and begin overwriting the previously drawn line. 当我的线到达可见区域的末尾时,我想回到起点并开始覆盖先前绘制的线。 Essentially the pen would go from left to right, jump back to the left and repeat. 本质上,笔会从左到右移动,然后跳回左侧并重复。

The only way I can think to accomplish this is to continuously update the portion of the data set that needs to change and redraw. 我认为实现此目标的唯一方法是不断更新需要更改和重绘的数据集部分。 I'm concerned this will force the entire line to be redrawn which will not be acceptable in terms of performance. 我担心这将迫使整个生产线重新绘制,这在性能方面是不可接受的。

What am I not thinking of? 我在想什么呢? What is the best/optimized way to accomplish this task? 完成此任务的最佳/最佳方式是什么?

var live_data = [...];// live values you should write and rewrite in this array
...
var live_path = svg.append("svg:path").attr("d", live_line_form(live_data));
...

and the d attribute formatter: d属性格式化程序:

function live_line_form(array_of_values){
    var d = "M", x_domain = 1.0, y_domain = 1.0;
    array_of_values.forEach(function(val, i){
        d = d + i * x_domain + "," + val * y_domain + " "
    });
    return(d.trim);
}

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

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