大型 TChart 绘制需要很长时间

发布于 2024-10-13 15:35:25 字数 697 浏览 5 评论 0原文

置顶帖子:我已经接受了答案,但它对我不起作用。我将发布一个新问题,强调 Delphi 7。感谢所有给予的人一些好的输入


我在一小时内以一秒的间隔进行了测量。

我之前有一个问题,更新 TStringGrid 需要 45 秒,并设法将其降低到“比眼睛能看到的速度更快”。部分是通过移动循环的一些计算和数据库相关功能,但是 - 令我惊讶的是 - 真正产生差异的更改是在循环之前将 strindgrid 的 rowCount 设置为 3600,而不是在循环内递增它。

现在我在 TChart 上遇到了类似的问题。也许我尝试预分配图表?因此,我可以 Chart1.Series[0].Count := 3600,但不能使用 AddXy()Add() >,那么我如何明确设置系列值?

我有一个非常简单的图表,y 轴上有浮点数,x 轴上有小时:秒

任何人都可以帮忙,或者建议另一种加快图表绘制速度的方法吗?


更新:一些人建议使用 TFastLineSeries,但我不知道如何使用。

啊哈 - 双击图表,显示所有系列,选择一个并显示所有系列。单击更改

Top post: I have accepted an answer,but it doesn't work for me. I will post a new question, stressing Delphi 7. Thanks to all who gave some good input


I have measurements taken at one second intervals over an hour.

I had a previous question where it was taking 45 seconds to updates a TStringGrid and managed to get that down to "faster than the eye can see". Partly by moving some computation and database related functionality of of the loop, but - surprisingly to me - the change that really made the difference was setting the strindgrid's rowCount to 3600 before the loop rather than incrementing it inside the loop.

Now I have a similar problem with a TChart. Maybe if I try preallocating the chart? So, I could Chart1.Series[0].Count := 3600, but than I can't use AddXy() or Add(), so how would I explicitly set the values in series?

I have a very simple chart, with Floats on the y-axis and hour:seconds on the x-axis

Can anyone help, or suggest another way to speed up chart drawing?


Update: several have suggested using TFastLineSeries, but I don't see how.

Aha - double click on the Chart, to show all series, select one & click change

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

分开我的手 2024-10-20 15:35:25

您可以在 Steema 网站 上找到有关快速图表的“官方”建议

You can find the "official" recommendations about fast charting on Steema website

恬淡成诗 2024-10-20 15:35:25

我设法在眨眼间绘制数百万个数据点。我是这样做的:
您可以做的是为 X 和 Y 值创建两个数组,用您的值填充它们,然后将这些数组添加到图表中。例如:

var
  XValues, YValues: array of double; 
begin

  SetLength(XValues, numberofValues);
  SetLength(YValues, numberofValues);

  for ix := 0 to numberofValues - 1 do 
  begin
    XValues[ix] := ...your values
    YValues[ix] := ...your values
  end;

  Chart.Series[0].XValues.Value := TChartValues(XValues);
  Chart.Series[0].XValues.Count := high(XValues);
  Chart.Series[0].XValues.Modified := true;
  Chart.Series[0].YValues.Value := TChartValues(YValues);
  Chart.Series[0].YValues.Count := high(YValues);
  Chart.Series[0].YValues.Modified := True;

使用 TFastLineSeries 而不是常规的 TLineSeries 也可以加快绘图速度。使用 FastlineSeries 时,您还拥有 DrawAllPoints 属性。当设置为 false 时,绘图速度会更快。然后,TChart 将跳过与屏幕上其他数据点共享相同 X 位置的数据点。它只会画出其中的第一点。

您可以在此处找到 DrawAllPoints 选项: alt text

I manage to draw millons of datapoints in a blink of an eye. Here's how I do it:
What you can do is to create two arrays for the X and Y Values, fill them with your values and then these arrays to your chart. For example:

var
  XValues, YValues: array of double; 
begin

  SetLength(XValues, numberofValues);
  SetLength(YValues, numberofValues);

  for ix := 0 to numberofValues - 1 do 
  begin
    XValues[ix] := ...your values
    YValues[ix] := ...your values
  end;

  Chart.Series[0].XValues.Value := TChartValues(XValues);
  Chart.Series[0].XValues.Count := high(XValues);
  Chart.Series[0].XValues.Modified := true;
  Chart.Series[0].YValues.Value := TChartValues(YValues);
  Chart.Series[0].YValues.Count := high(YValues);
  Chart.Series[0].YValues.Modified := True;

What also speeds up the drawing is using the TFastLineSeries instead of the regular TLineSeries. When using the FastlineSeries you also have the property DrawAllPoints. When set to false the drawing is even faster. TChart will then skip datapoints that share the same X Position with other datapoints on the screen. It will only draw the first point of these.

This is where you find it the DrawAllPoints option: alt text

没企图 2024-10-20 15:35:25

我只想对迈克尔·施穆克斯的回答发表评论。使用 High(XValues) 设置系列的计数值会导致数组中的最后一项不显示。这是因为 high(XValues) 返回数组的最高索引,而不是数组的大小。

当然,只有当添加的项目数量非常少时才会注意到这一点。

Chart.Series[0].XValues.Count := high(XValues) + 1;

I would just like to comment on the Michael Schmooks answer. Using High(XValues) to set the Count value for the series causes the last item in the array not to be displayed. This is because high(XValues) returns the highest index of the array, and not the size of the array.

Of course, this is only noticed when a very low nr of items happens to be added.

Chart.Series[0].XValues.Count := high(XValues) + 1;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文