Display "virtual" series?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
dummzeuch
Newbie
Newbie
Posts: 1
Joined: Fri Jun 21, 2024 12:00 am

Display "virtual" series?

Post by dummzeuch » Mon Jun 16, 2025 12:21 pm

I would like to display a chart with data that is too large to be stored in memory, so using regular TLineSeries or TFastLineSeries won't work. The data is also not stored in a database but in a proprietary binary file format, so using a TDbChart also won't work for this.

Is there any kind of line series that e.g. has a callback for getting the Y value for a given X value or something similar?
Or any other way to achieve this?

Of course I could create a line series that only contains data for a given span of X values and update the data in the series every time the user pans the chart horizontally, but I hope there is a simple way of doing this.

Yeray
Site Admin
Site Admin
Posts: 9709
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Display "virtual" series?

Post by Yeray » Mon Jun 16, 2025 4:44 pm

Hello,

Indeed, the easier approach would be to dynamically load the data you need. Ie:
load_dinamically.png
load_dinamically.png (17.3 KiB) Viewed 1040 times

Code: Select all

var
  Chart1: TChart;
  Series1: TPointSeries;

const FileName= 'D:\Downloads\data.csv';
const step=50;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1:=TChart.Create(Self);

  with Chart1 do
  begin
    Parent:=Self;
    Align:=alClient;
    Color:=clWhite;
    Gradient.Visible:=False;
    Walls.Back.Color:=clWhite;
    Walls.Back.Gradient.Visible:=False;
    Legend.Hide;
    View3D:=False;

    Series1:=TPointSeries(AddSeries(TPointSeries));
    with Series1 do
    begin
      Pointer.Size:=2;
      LoadData(0, step*2-1);
    end;
  end;
end;

procedure TForm1.LoadData(AStartLine, AEndLine: Integer);
var
  Reader: TStreamReader;
  CurrentLine: Integer;
  tmpLine: string;
  tmpFields: TArray<string>;
begin
  Series1.Clear;

  Reader:=TStreamReader.Create(FileName);
  try
    CurrentLine:=0;
    while (not Reader.EndOfStream) and (CurrentLine <= AEndLine) do
    begin
      if (CurrentLine >= AStartLine) and (CurrentLine <= AEndLine) then
      begin
        tmpLine:=Reader.ReadLine;
        tmpFields:=tmpLine.Split([';']);

        if Length(tmpFields)<2 then
          Continue;

        Series1.AddXY(StrToInt(tmpFields[0]), StrToFloat(tmpFields[1]));
      end
      else
        Reader.ReadLine;

      Inc(CurrentLine);
    end;
  finally
    Reader.Free;
  end;

  BPrev.Enabled:=Series1.XValues.First>0;
  BNext.Enabled:=Series1.XValues.Last<999;
end;

procedure TForm1.BPrevClick(Sender: TObject);
begin
  if Series1.Count=0 then
    Exit;

  LoadData(Round(Series1.XValues.First)-step,
           Round(Series1.XValues.Last)-step);
end;

procedure TForm1.BNextClick(Sender: TObject);
begin
  if Series1.Count=0 then
    Exit;

  LoadData(Round(Series1.XValues.First)+step,
           Round(Series1.XValues.Last)+step);
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply