简体   繁体   English

如何在不重绘的情况下将单个数据点添加到 D3 中的折线图

[英]How to add a single data point to a line graph in D3 without redrawing

I'm working on replacing a dynamic chart implemented in highcharts. The current implementation is a line-area chart that expands over time with incoming streaming data, so the replacement needs to be dynamically alterable, and preferrably animated.我正在努力替换在 highcharts 中实现的动态图表。当前的实现是一个线面积图,随着传入的流数据随时间扩展,因此替换需要动态可变,最好是动画。

Currently I'm looking at D3 for the replacement.目前我正在寻找 D3 的替代品。 There are a few examples I've found which show that there may be something similar which is possible, such as the charts for streaming data found here , but in this example the line is redrawn at every iteration.我发现了一些示例,这些示例表明可能存在类似的东西,例如此处的流数据图表,但在此示例中,该线在每次迭代时都会重新绘制。 It's not terribly inefficient as the visualization is limited to a fixed window of data, but in my case a high volume of data needs to be displayed from start to finish as the data streams in. Redrawing the chart at every addition will likely result in rapid performance loss.它并不是非常低效,因为可视化仅限于固定的 window 数据,但在我的情况下,随着数据流的进入,需要从头到尾显示大量数据。每次添加时重新绘制图表可能会导致快速性能损失。

In D3, is there a method of adding a single segment to an existing plot that does not require a redraw?在D3中,是否有一种方法可以在不需要重绘的情况下将单个段添加到现有的plot?

I ended up abandoning D3 as it required too much development to make it as presentable as an interactive chart that was ready out-of-the-box, but I did figure out how to do what I was thinking.我最终放弃了 D3,因为它需要太多的开发才能使其像开箱即用的交互式图表一样美观,但我确实想出了如何做我想做的事情。

Instead of re-adding a new line with additional points at every iteration, I ended up using a path component which allows additional points to be added progressively.我没有在每次迭代时重新添加带有附加点的新行,而是最终使用了一个允许逐步添加附加点的路径组件。 The path does have to be re-rendered and generates a short svg path string, so I'm not exactly sure which method is more efficient, but a short path string reduces complexity of the resulting html in the case that one were to add multiple lines to the plot, one for each segment.路径确实必须重新呈现并生成一个短的 svg 路径字符串,所以我不确定哪种方法更有效,但短路径字符串降低了生成的复杂性 html 在一个人要添加多个的情况下线路到 plot,每个航段一个。

If an addition to the path involves only the generation of a new string using concatenation of the original then I imagine this could be much more efficient than iterating through an array of series data that grows at every update.如果路径的添加仅涉及使用原始字符串的连接生成新字符串,那么我想这可能比遍历每次更新时增长的系列数据数组更有效。

The result was fast enough to keep up with streaming data without any visible slowing of the UI, but it was just unfortunate that I needed something a little more developed.结果速度足够快,可以跟上流数据,而 UI 没有任何明显的减慢,但不幸的是,我需要一些更发达的东西。

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

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