Recent

Author Topic: DataPointHintTool - more than one kind of series - bug in component?  (Read 1868 times)

Nicole

  • Hero Member
  • *****
  • Posts: 970
There are some threads of mine with this topic and there is a demo, how it may work.
And it works - assumed that I do not have more than one kind of series.

Usually I have as main point of interest a candlestick chart, which means a TopenhighlowcloseSeries. (To this chart I add more series later at design time, mostly TLineSeries).

To this TAChart  I add a ChartTool and there a TDataPointHint tool. There
I add an OnHInt-Event, which my look like this. Nothing special, just taken the code of the TAAchart help / demo.

Code: Pascal  [Select][+][-]
  1.   with TDatapointHintTool(ATool) do begin  
  2.     ser := Series as TChartSeries;
  3.     punkt := PointIndex;
  4.   end;
  5.  
  6.   if ser <> nil
  7.      then AHint := DateToStr(ser.GetXValue(punkt)) +'  ' + FloatToStr(ser.GetYValue(punkt))
  8.      else  AHint := '';  
  9.  

This works fine, - until I add a second kind of series as TLineSeries or TBarSeries.

The first run-attempt may work fine as well.
But sooner or later, the troubles are that hard, that first my project does not compile any more and later my whole operating system says good-bye to me. Long lists of error-messages pop up (I posted them already, but do not think, they are useful).
These error-messages persist even if I close Lazarus and restart it.

A restart of my Win 7 VM helps as only solution.

Then I can re-start Lazarus, go to my TAChart and remove the property setting "tools" pointing at the tool containing the TPointHintTool.

Then my operating system and project is stable again.
This is the ONLY thing, which helps. To put the whole content of the On-Hint event into commentary does not help any more.

This does not happen in only one of my charts, but in the meanwhile of three, which work completely differently.
These charts are fed by a database and I am not good at databases and cannot extract it (and I must not do it).
Yes, you need a demo, but I cannot provide. I know, this is not a good thing.

So here comes my question to the plenum:
Does anybody use a (firebird-)database with Candelstick charts AND (!!) several further types of dataseries (as TLineSeries) together with it? And the ChartHintTool works fine for him?

wp

  • Hero Member
  • *****
  • Posts: 11906
Re: DataPointHintTool - more than one kind of series - bug in component?
« Reply #1 on: February 11, 2023, 04:51:42 pm »
I think you don't get closer to a solution of this problem by opening more and more threads about it...

Anyway, I restructured the demo in the other threads such that the finance data read from Yahoo are stored in a DBase database file, and the chart is created from that. And it is working too.

How do you get the data out of the database into the series? Show me the related code. Do not use a TDBChartSource - it is has very bad performance -, but iterate over the dataset and add the extracted values into the series as usual. Like in the attached demo.

P.S.
Initially I wanted to create a Firebird database, but my Firebird is broken all of a sudden, error Unable to complete network request to host "xnet://Global\FIREBIRD"

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: DataPointHintTool - more than one kind of series - bug in component?
« Reply #2 on: February 11, 2023, 07:20:33 pm »
This is an example of how I add the data in one case (I really have many charts and many ways to add).
As I asked here for advice, I avoid the "TDBChartSource" in EVERY case.
Somebody told me, that it would be better not to use it.

Code: Pascal  [Select][+][-]
  1.  while not IBQuery_Zeichne.EOF do begin  // zeichnet das Chart als Candles
  2.        SeriesCandles.AddXOHLC(
  3.          IBQuery_Zeichne.FieldByName('FK_JDATUM').AsDateTime,
  4.          IBQuery_Zeichne.FieldByName('O').AsFloat,
  5.          IBQuery_Zeichne.FieldByName('H').AsFloat,
  6.          IBQuery_Zeichne.FieldByName('L').AsFloat,
  7.          IBQuery_Zeichne.FieldByName('C').AsFloat
  8.          );
  9.       Volume.AddXY(IBQuery_Zeichne.FieldByName('FK_JDATUM').AsDateTime,IBQuery_Zeichne.FieldByName('Volume').AsFloat);
  10.       OpenInterest.AddXY(IBQuery_Zeichne.FieldByName('FK_JDATUM').AsDateTime,IBQuery_Zeichne.FieldByName('OpenInterest').AsFloat);
  11.  
  12.       s1:='';
  13.       s1:= s1 + DateToStr(IBQuery_Zeichne.FieldByName('FK_JDATUM').AsDateTime) + ': ';
  14.       //s1 := s1 + ' o=' + FloatToStrF(IBQuery_Zeichne.FieldByName('O').AsFloat, ffFixed, 4, 4) + '/';   // das funktioniert zwar, doch macht die Zeilen zu lange
  15.       //s1 := s1 + 'h=' + FloatToStrF(IBQuery_Zeichne.FieldByName('H').AsFloat, ffFixed, 4, 4) + '/';
  16.       //s1 := s1 + 'l=' + FloatToStrF(IBQuery_Zeichne.FieldByName('L').AsFloat, ffFixed, 4, 4) + '/';
  17.       s1 := s1 + 'c=' + FloatToStrF(IBQuery_Zeichne.FieldByName('C').AsFloat, ffFixed, 4, 4) + '/';
  18.       s1 := s1 + 'Vol=' + FloatToStrF(IBQuery_Zeichne.FieldByName('Volume').AsFloat, ffFixed, 4, 0) + '/';
  19.       s1 := s1 + 'oi=' + FloatToStrF(IBQuery_Zeichne.FieldByName('OpenInterest').AsFloat, ffFixed, 4, 0);
  20.       self.RichMemo_Legende.Lines.Add(s1);
  21.  
  22.       if IBQuery_Zeichne.RecNo = IBQuery_Zeichne.RecordCount - 1  // der letzte Tag wird
  23.       then begin                                         // für die Überschrift ausgelesen
  24.             open_:=IBQuery_Zeichne.FieldByName('O').AsFloat;
  25.             high_:=IBQuery_Zeichne.FieldByName('H').AsFloat;
  26.             low_:=IBQuery_Zeichne.FieldByName('L').AsFloat;
  27.             close_:=IBQuery_Zeichne.FieldByName('C').AsFloat;
  28.             dat_:=IBQuery_Zeichne.FieldByName('FK_JDATUM').AsDateTime;
  29.       end;
  30.       IBQuery_Zeichne.Next;
  31.                                     end;
       


Thank you for your demo.
It would be great, if I only would view the result. It does exactly what I want and need.
Never the less it is not usable for me.
I see 18 warnings and about 500 hints (file attached).

My ability in programming is not skilled enough to deal with them.
If the basic of the code looks like this: Don't you think it possible there may be some of those 18 warnings justified and able to produce my system crashes?
                                   

wp

  • Hero Member
  • *****
  • Posts: 11906
Re: DataPointHintTool - more than one kind of series - bug in component?
« Reply #3 on: February 11, 2023, 08:01:16 pm »
This code looks correct.

You could take the piece of code that you showed and replace it as follows to get rid of the database for a demo for me:
Code: Pascal  [Select][+][-]
  1. const
  2.   N = 20;
  3. var
  4.   i: Integer;
  5.   D: TDateTime;
  6.   O, H, L, C, V, OI: Double;
  7. ...
  8.   for i := 0 to N-1 do begin
  9.     // Dummy date: the last N days
  10.     D := Date() - (N-1) + i;
  11.     // Random values for O, H, L, C, making sure that H is the largest and L the smallest of these numbers
  12.     O := random * 100;
  13.     C := random * 100;
  14.     repeat
  15.       L := random * 100;
  16.       H := random * 100;
  17.     until (H >= L) and (H >= O) and (H >= C) and (L <= O) and (L <= C);
  18.     V := random* 1E6;
  19.     OI := random*10;
  20.  
  21.     SeriesCandles.AddXOHLC(
  22.       D,   // IBQuery_Zeichne.FieldByName('FK_JDATUM').AsDateTime,
  23.       O,   // IBQuery_Zeichne.FieldByName('O').AsFloat,
  24.       H,   // IBQuery_Zeichne.FieldByName('H').AsFloat,
  25.       L,    // IBQuery_Zeichne.FieldByName('L').AsFloat,
  26.       C   // IBQuery_Zeichne.FieldByName('C').AsFloat
  27.     );
  28.  
  29.     Volume.AddXY(D, V);  // IBQuery_Zeichne.FieldByName('FK_JDATUM').AsDateTime,IBQuery_Zeichne.FieldByName('Volume').AsFloat);
  30.    
  31.      OpenInterest.AddXY(D, OI);  // OpenInterest.OpenInterest.AddXY(IBQuery_Zeichne.FieldByName('FK_JDATUM').AsDateTime,IBQuery_Zeichne.FieldByName('OpenInterest').AsFloat);
  32.  
  33.       s1:='';
  34.       s1:= s1 + DateToStr(D) + ': ';
  35.       //s1 := s1 + ' o=' + FloatToStrF(O, ffFixed, 4, 4) + '/';   // das funktioniert zwar, doch macht die Zeilen zu lange
  36.       //s1 := s1 + 'h=' + FloatToStrF(H, ffFixed, 4, 4) + '/';
  37.       //s1 := s1 + 'l=' + FloatToStrF(L, ffFixed, 4, 4) + '/';
  38.       s1 := s1 + 'c=' + FloatToStrF(C, ffFixed, 4, 4) + '/';
  39.       s1 := s1 + 'Vol=' + FloatToStrF(V, ffFixed, 4, 0) + '/';
  40.       s1 := s1 + 'oi=' + FloatToStrF(OI, ffFixed, 4, 0);
  41.       self.RichMemo_Legende.Lines.Add(s1);
  42.  
  43.       if i = N-1 then
  44. //      if IBQuery_Zeichne.RecNo = IBQuery_Zeichne.RecordCount - 1  // der letzte Tag wird
  45.       then begin                                         // für die Überschrift ausgelesen
  46.             open_:=O;  // IBQuery_Zeichne.FieldByName('O').AsFloat;
  47.             high_:=H; // IBQuery_Zeichne.FieldByName('H').AsFloat;
  48.             low_:=L;  // IBQuery_Zeichne.FieldByName('L').AsFloat;
  49.             close_:=C;  //IBQuery_Zeichne.FieldByName('C').AsFloat;
  50.             dat_:=D;  //IBQuery_Zeichne.FieldByName('FK_JDATUM').AsDateTime;
  51.       end;
  52. //      IBQuery_Zeichne.Next;
  53.   end;

I know the huge number of hints/warnings is not nice. But look carefully: only about 15 of them originate in your own code, the rest originates in the LCL. In Laz/main a lot of the hints in TAChart have been removed, but some of them are reappearing - it's a fight against wind-mills... And in the LCL there are even more.

I am very sure that the hints/notes generated for your own code are harmless.

Hints usually are harmless. Warnings basically are more critical; the warning that a parameter passed to a procedure is not used usually is harmless, however, could mean that there is a typo in the code. Also, the "variable not initialized" warning should be checked - in 99% harmless, but I've had cases when this helped me to find a bug.

In the particular case of my sample project you see all the LCL/TAChart/etc hint/warnings because I added the option "-gw3" to "Additions and overrides" of the project options; this allows me to enter the LCL and TAChart code with the debugger. Normally I put this into the project file, but this time it moved into the project options incidentally.

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: DataPointHintTool - more than one kind of series - bug in component?
« Reply #4 on: February 11, 2023, 08:31:59 pm »
Thank you.
I'll work on with it next week and keep you informed.


 

TinyPortal © 2005-2018