Large TChart takes a long time to draw

我的梦境 提交于 2019-12-04 04:34:02

问题


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


回答1:


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:




回答2:


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




回答3:


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;


来源:https://stackoverflow.com/questions/4767684/large-tchart-takes-a-long-time-to-draw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!