使用 WPF 绘制数千个数据点的最高效方法? [英] Most performant way to graph thousands of data points with WPF?

查看:38
本文介绍了使用 WPF 绘制数千个数据点的最高效方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个图表来显示财务数据.当我使用 PathGeometry 以及 PathFigureLineSegment 绘制少于 10.000 个点显示为连接线时,性能很好.但是现在我需要同时显示多达 100.000 个点(不滚动),并且它已经非常慢了 50.000 个点.我在考虑 StreamGeometry,但我不确定,因为它与将信息作为字节流存储的 PathGeometry 基本相同.有没有人有一个想法来提高这个性能,或者也许有人已经做过类似的事情?

这些数据点一旦绘制就不会改变,所以如果有可能对其进行优化,请告诉我(线段现在被冻结).

我尝试了 StreamGeometry.由于某种原因,创建图形花费的时间更长,但这不是问题.绘制所有点后在图表上绘制仍然和之前的方法一样慢.我认为 WPF 处理的数据点太多了.

我进行了一些实验,我注意到通过将以前的 double 坐标转换为 int 以防止 WPF 抗锯齿子像素线,性能有所提高.

感谢所有建议减少线段数量的回复.我已经将它们减少到最多两倍于阶梯线的水平分辨率,最多是简单线的水平分辨率,现在性能非常好.

解决方案

我会考虑对您尝试渲染的点数进行下采样.您可能有 50,000 个数据点,但不太可能将它们全部显示在屏幕上;即使您在一个显示器中绘制了每个点,您也需要 100,000 像素的水平分辨率来绘制商场!即使在 D3D 中,也需要大量绘制.

由于您更有可能拥有 2,048 像素之类的东西,您不妨减少正在绘制的点并绘制一条适合屏幕且只有几千个顶点的近似曲线.例如,如果用户绘制了一个包含 10000 个点的时间框架,那么在绘制之前将这 10000 个点降采样到 1000.您可以尝试多种技术,从简单平均到中值邻域再到高斯卷积(我的建议)双三次插值.绘制大于屏幕分辨率 1/2 的任意数量的点将是一种浪费.>

当用户放大图形的一部分时,您可以重新采样以获得更高的分辨率和更准确的曲线拟合.

I have written a chart that displays financial data. Performance was good while I was drawing less than 10.000 points displayed as a connected line using PathGeometry together with PathFigure and LineSegments. But now I need to display up to 100.000 points at the same time (without scrolling) and it's already very slow with 50.000 points. I was thinking of StreamGeometry, but I am not sure since it's basically the same as a PathGeometry stroring the information as byte stream. Does any one have an idea to make this much more performant or maybe someone has even done something similar already?

EDIT: These data points do not change once drawn so if there is potential optimizing it, please let me know (line segments are frozen right now).

EDIT: I tried StreamGeometry. Creating the graphic took even longer for some reason, but this is not the issue. Drawing on the chart after drawing all the points is still as slow as the previous method. I think it's just too many data points for WPF to deal with.

EDIT: I've experimented a bit and I noticed that performance improved a bit by converting the coordinates which were previously in double to int to prevent WPF anti-aliasing sub-pixel lines.

EDIT: Thanks for all the responses suggesting to reduce the number of line segments. I have reduced them to at most twice the horizontal resolution for stepped lines and at most the horizontal resolution for simple lines and the performance is pretty good now.

解决方案

I'd consider downsampling the number of points you are trying to render. You may have 50,000 points of data but you're unlikely to be able to fit them all on the screen; even if you charted every single point in one display you'd need 100,000 pixels of horizontal resolution to draw them all! Even in D3D that's a lot to draw.

Since you are more likely to have something like 2,048 pixels, you may as well reduce the points you are graphing and draw an approximate curve that fits onto the screen and has only a couple thousand verts. If for example the user graphs a time frame including 10000 points, then downsample those 10000 points to 1000 before graphing. There are numerous techniques you could try, from simple averaging to median-neighbor to Gaussian convolution to (my suggestion) bicubic interpolation. Drawing any number of points greater than 1/2 the screen resolution will simply be a waste.

As the user zooms in on a part of a graph, you can resample to get higher resolutions and more accurate curve fitting.

这篇关于使用 WPF 绘制数千个数据点的最高效方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆