Recent

Author Topic: How to populate my TAChart by a query?  (Read 1415 times)

Nicole

  • Hero Member
  • *****
  • Posts: 970
How to populate my TAChart by a query?
« on: September 12, 2022, 06:53:58 pm »
I am afraid, I started this thread
https://forum.lazarus.freepascal.org/index.php/topic,59663.msg445469.html#msg445469

and this:
https://forum.lazarus.freepascal.org/index.php/topic,60408.msg451614.html#msg451614

and cannot do it.
My datapoints do not show up!

What I have:
TChart is on my form and looks good, a line "series1" is added.
TCharts shows up at runtime, but without any data
An IBQuery1 is on my form. The SQL request is generated and writes the results at runtime to a RichMemo, working fine.

So the IBQuery1 gives me the wanted values at runtime.
What can I do, that those values are shown in my TAChart.series1?

I tried strange things at design-time, added a DataSource and so, everything looks false.
What I would expect, is a property which would allow me to key in "IBQuery1", set the thing to active and the chart to appear. This is the way Tee works and this may make me blind for the way TAChart does it.
At the moment, there is not even a drop-down list anywhere this would allow me to select "IBQuery1".

I bet the solution is easy, if you know it.
Thanks in advance.

Arioch

  • Sr. Member
  • ****
  • Posts: 421
Re: How to populate my TAChart by a query?
« Reply #1 on: September 12, 2022, 07:12:59 pm »
your second link says

Quote
Drop a TDBChartSource on the form. Set its Datasource property to the Datasource to which your dataset is connected.

Did you do it? with exactly TDBChartSource ?

that link also says

Quote
but there are two demos in the TAChart folder of your Lazarus installation (components/tachart/demo/db and

Did you opened that project and learnt which ocmponents were put to the form and how their properties do interact ?

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: How to populate my TAChart by a query?
« Reply #2 on: September 12, 2022, 07:44:28 pm »
Just follow the steps that I wrote recently in https://forum.lazarus.freepascal.org/index.php/topic,60408.msg451623.html#msg451623.

Since the internal operation of TDbChartSource is very inefficient it is not recommended to have it connected to a series permanently. Copy the DBChartSource over to a ListChartSource whenever the database is changed. See the attached demo with a FireBird database how this can be done.


Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: How to populate my TAChart by a query?
« Reply #3 on: September 12, 2022, 08:21:55 pm »
Thank you so much for the demo!
Yes, I followed the instructions exactly.

Where your property says "query1", - there is no option to fill in the correct query in my project. Shall be a fuzzy thing, the smart programmer did not think about. Can be a checkbox checked at 'login-prompt' or 'active' or such a thing which blocks the query to show up.

I will find the reason sooner or later and click by click compared with the demo.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: How to populate my TAChart by a query?
« Reply #4 on: September 12, 2022, 09:56:53 pm »
You connect the Query1 to the DataSource1.Dataset, and the DataSource1 to the DbGrid1.Datasource, DbNavigator1.Datasource, DbEdit1.Datasource, or whatever, among them also the DbChartSource1.Datasource.

Arioch

  • Sr. Member
  • ****
  • Posts: 421
Re: How to populate my TAChart by a query?
« Reply #5 on: September 13, 2022, 12:39:24 am »
I will find the reason sooner or later and click by click compared with the demo.

In another thread you argued against automatic conversion of projects and for manual transition Delphi -> Lazarus.

I would similarly argue the idea of db-aware Chart is poor one. Someone would close a db transaction, it closes all the queries in the transaction - and your query went blank, like other db-aware controls.
Alternatively you have transaction open for hours, until DB admins with growing desperation find you and kill you.

Would i code things like that i'd do intermediate internal storage, like this (assuming Unified Interbase library, but this pieces can be easily copy-pasted into IBX2 or any other FLOSS lib)

Code: Pascal  [Select][+][-]
  1. type RMyData = record x, y1, y2, y3, ..... end; // he data for charts
  2.  
  3. var Data: TList<RMyData>;
  4.       Cell: RMyData;
  5.       q: TIBQuery;
  6.  
  7. ....
  8. begin
  9.     q.Open;
  10.     Data.Clear;
  11.     for Cell in q.AllRows<RMyData> do
  12.       Data.Add(Cell);
  13.     q.Close; // and commit transaction, perhaps, too
  14.  
  15.     Chart1.Clear;
  16.     for Cell in Data do begin
  17.       Chart1.series[0].Add(Cell.x, Cell.y1);
  18.       Chart1.series[1].Add(Cell.x, Cell.y2);
  19.       Chart1.series[2].Add(Cell.x, Cell.y3);
  20.       ...
  21.    end;
  22.  

Kind of so.

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: How to populate my TAChart by a query?
« Reply #6 on: September 13, 2022, 09:18:17 am »
@ WP Thank you for the instructions!

@Arioch: This is true.
and thank you for the code snipets. I will compare them with mine.

Many charts I draw like this in Delphi. I use(d) TeeChart Pro there.
Cross fingers for their migration, which I have not started yet.

TeeChart Pro is great, but they want more money for every update of Delphi. Sure, this is ok, they have a lot of work with every new Delphi version. Nevertheless, it does not pay for me as person to invest so much money. I am no software-reseller.

What is NOT ok to me, that I have to pay Embarcadero for a new version of Delphi just to get a version with the most severe bugs removed. Working with Lazarus now, I am aware how much afford it was to use workarounds of the Delphi IDE bugs. They do not even think of upgrading the software as they delivered poor quality! They want to sell me a new version.

e.g. my Delphi IDE freezes every some hours because of RAM overrun, which is caused by a setting of the IDE, which I need. Bugs in components are corrected in Lazarus within some days, - they (Embarcadero) keep them for years or do provide no update at all. So the free thing is much better than the high-price one?!

When this policy leads to a shutdown of Embarcadero one day, - I do not want to be dependent on Delphi anymore.

« Last Edit: September 13, 2022, 09:22:19 am by Nicole »

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: How to populate my TAChart by a query?
« Reply #7 on: September 13, 2022, 10:39:19 am »
Many charts I draw like this in Delphi. I use(d) TeeChart Pro there.
Cross fingers for their migration, which I have not started yet.
Be warned: Porting of units with Delphi TeeChart to Lazarus TAChart is a very difficult thing because they work completely different in spite of using the same component and property names. While TeeChart has stuffed many features into specific properties TAChart requires you to combine several components. Before attempting any conversion get a solid understanding of how to use TAChart. There is a bunch of tutorials as well as a lengthy documentation in the wiki (https://wiki.lazarus.freepascal.org/Category:TAChart); I also once began an article about comparing both libraries (https://wiki.lazarus.freepascal.org/Comparing_TAChart_with_Delphi%27s_TeeChart_Standard), but eventually gave up to complete this endless list.

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: How to populate my TAChart by a query?
« Reply #8 on: September 13, 2022, 11:55:36 am »
Thank you for the warning.
I have a bundle of drawing functions, of which I am not quite sure, if to migrate them or to leave behind....

These tutorials I tried to read already. They are very basic. Anywhere I have even bookmarked how to migrate from TeeChart (I do not have! I have TeeChart Pro) to TAChart. I am not sure, if I will manage it by these tutorials.

The query thing I tried in the meanwhile and now it looks correct. However the chart points to not show up.
How to test?
I have a series property where I can click "active". I click and nothing happens (the good news are that the db does not drop an exception).

I am used from TeeChart to set up a chart and then select "active" and the chart appears at design-time. Will this work in TAChart at all?

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: How to populate my TAChart by a query?
« Reply #9 on: September 13, 2022, 12:43:23 pm »
I am used from TeeChart to set up a chart and then select "active" and the chart appears at design-time. Will this work in TAChart at all?
Be careful with your wording - I have to read so much between the lines... A chart has no "active" property, in contrast to a series. So you probably are talking of a series?

When you add a series to a chart it is "active" by default. But you won't see it in the chart because it has no data (In TeeChart, I think it displays random dummy data). Data are always provided by a ChartSource, and even if you simply "AddXY" data to the series itself they are stored by an internal ListChartSource. So, understanding the chartsources is a fundamental thing in understanding TAChart.

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: How to populate my TAChart by a query?
« Reply #10 on: September 13, 2022, 06:09:32 pm »
Thank you all, you helped me! :-*
My chart draws something for the first time.   :D

I could not make it draw from my query1 and so I took the solution with
Series1.Add(..);
in the iteration
'while not query1.eof';

Which indeed has several nice advantages in my case.

Up to the next Frame! And the other charts. Not sure, how they will work.

 

TinyPortal © 2005-2018