Recent

Author Topic: Tchart Nitrogen simulation  (Read 1061 times)

flori

  • Full Member
  • ***
  • Posts: 185
Tchart Nitrogen simulation
« on: March 19, 2021, 08:19:45 pm »
Hi everyone!
Is it possible to simulate  (start/and) data from a database on Tchart?
I attached demo project.  I have a lot of measurements  it should be presented in real time.
Thank u.

wp

  • Hero Member
  • *****
  • Posts: 8568
Re: Tchart Nitrogen simulation
« Reply #1 on: March 19, 2021, 09:50:40 pm »
There are several examples of real-time charts here in this forum. Please use the forum search.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

wp

  • Hero Member
  • *****
  • Posts: 8568
Re: Tchart Nitrogen simulation
« Reply #2 on: March 19, 2021, 09:59:48 pm »
Tried to run your demo, but again I cannot get it work. Please rewrite your demo such that a simple database is used. I don't see why I should install Firebird and the ZEOS components just the help you with a TAChart question.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

flori

  • Full Member
  • ***
  • Posts: 185
Re: Tchart Nitrogen simulation
« Reply #3 on: March 19, 2021, 10:58:47 pm »
ok. I converted some data to dbf.

wp

  • Hero Member
  • *****
  • Posts: 8568
Re: Tchart Nitrogen simulation
« Reply #4 on: March 20, 2021, 12:07:59 am »
What exactly is the problem?

At least, I can fix the crash of your demo program. I am not very happy about TDbChartSource being in TAChart. It is a very "stupic" datasource, relies heavily on the RecNo and RecordCount properties of the dataset which are known to be very unreliable, in particular with server databases (but even with the TDbf in your example RecordCount returns a wrong value).

It is highly recommended to copy the dataset records into a TListChartSource, either a separate component or the built-in ListSource of the series:
Code: Pascal  [Select][+][-]
  1. var
  2.   NitrogenField: TField;
  3.   i: Integer;
  4. begin
  5.   // Copy the dataset to a ListChartSource. Do not use DBChartSource.
  6.   NitrogenField := Dbf1.FieldByName('Nitrogen');
  7.   Dbf1.First;
  8.   i := 1;
  9.   while not Dbf1.EoF do
  10.   begin
  11.     ListChartSource1.Add(i, NitrogenField.AsFloat);
  12.     Dbf1.Next;
  13.     inc(i);
  14.   end;
  15. end;

Since your sample code does not provide a field for the x values, I used a counter variable (i) for x.

After these changes in the FormCreate event (and assigning the ListChartSource1 to the Source property of the series, instead of the DBChartSoruce), your demo no longer crashes.
« Last Edit: March 20, 2021, 01:09:12 am by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

flori

  • Full Member
  • ***
  • Posts: 185
Re: Tchart Nitrogen simulation
« Reply #5 on: March 20, 2021, 09:34:55 am »
WP thank you. So when I use ZEOS component and Tchart with dbchartsource I need to copy the dataset into TlistChartSource....Because the dbchartsource records is  unreliable.
After copy data into TlistChartSource is it possible to simulate on Tchart with Timer? 
The list TlistChartSource  data can be assigned to a Timer?

wp

  • Hero Member
  • *****
  • Posts: 8568
Re: Tchart Nitrogen simulation
« Reply #6 on: March 20, 2021, 10:49:57 am »
I don't know what you mean exactly. When you want to say that you want to read the database periodically to display the data in a chart: of course this is possible. Add a timer with an appropriate (not too small) interval and in the OnTimer event refresh the dataset and copy the records to the listchartsource (do a ListChartSource.Clear at first in order to clear the series from the old data).
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018