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.
Display "virtual" series?
Re: Display "virtual" series?
Hello,
Indeed, the easier approach would be to dynamically load the data you need. Ie:
Indeed, the easier approach would be to dynamically load the data you need. Ie:
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,
![]() | Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) |
![]() ![]() ![]() ![]() ![]() ![]() |
Please read our Bug Fixing Policy |