Large TChart takes a long time to draw

笑着哭i 提交于 2019-12-01 21:13:35

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:

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

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