TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
-
P.Ferenc
- Newbie
- Posts: 1
- Joined: Fri Feb 19, 2021 12:00 am
Post
by P.Ferenc » Tue Apr 25, 2023 5:22 pm
Hi,
I would like to ask for help from people who use TeeChart (pro version, but I think have not different in standard verion)...
I use the following code to modify the Series values for the Chart (linked to database table field), but after running this code the Chart does not update on VCL form...
(Delphi 11.3 + Teechart Pro 2022.34 on windows 11 x64)
What am I missing or doing incorrectly?
Code: Select all
DataSource := DM.DataSourceTest;
DataSet := DataSource.DataSet;
FieldName := Series1.YValues.ValueSource;
DataSet.First;
while not DataSet.Eof do begin
FieldValue := DataSet.FieldByName(FieldName).AsInteger;
if FieldValue > 100 then begin
FieldValue := FieldValue - random(10);
DataSet.Edit;
DataSet.FieldByName(FieldName).AsInteger := FieldValue;
DataSet.Post;
end;
DataSet.Next;
end;
Series1.CheckDatasource;
dbChartTest.Invalidate;
dbChartTest.Refresh;
Application.ProcessMessages;
Thank you!
-
Yeray
- Site Admin
- Posts: 9614
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Tue May 09, 2023 12:16 pm
Hello,
This is a simple example of a
TDBChart
with a
TLineSeries
linked to a
TFDMemTable
updating values with a
TTimer
.
It seems to work fine for me here just calling
CheckDataSource
everytime the table is modified.
Code: Select all
var FDMemTable: TFDMemTable;
Chart: TDBChart;
Series: TLineSeries;
Timer: TTimer;
procedure TForm1.FormCreate(Sender: TObject);
var val: Double;
i: Integer;
begin
FDMemTable:=TFDMemTable.Create(Self);
FDMemTable.FieldDefs.Add('Price', ftInteger);
FDMemTable.CreateDataSet;
FDMemTable.Open;
val:=1000+Random(500);
for i:=0 to 10 do
begin
FDMemTable.AppendRecord([val]);
val:=val+Round(Random(10)-4.5);
end;
Chart:=TDBChart.Create(Self);
Chart.Parent:=Self;
Chart.Align:=alClient;
Chart.View3D:=False;
Chart.Legend.Hide;
Series:=TLineSeries(Chart.AddSeries(TLineSeries));
Series.DataSource:=FDMemTable;
Series.YValues.ValueSource:='Price';
Timer:=TTimer.Create(Self);
Timer.Interval:=1000;
Timer.OnTimer:=TimerTick;
Timer.Enabled:=True;
end;
procedure TForm1.TimerTick(Sender: TObject);
var val: Double;
begin
val:=Series.YValues.Last+Round(Random(10)-4.5);
FDMemTable.AppendRecord([val]);
Series.CheckDataSource;
end;