### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: DataPointHintTool - TOpenHighLowCloseSeries  (Read 339 times)

#### Nicole

• Hero Member
• Posts: 744
##### DataPointHintTool - TOpenHighLowCloseSeries
« on: January 27, 2023, 06:03:15 pm »
I got that stuck with the DataPointHintTool, that I gave up that project and started a new one and a different chart.

Below is the code, which does something.
"what" - see screenshot.

My question: How to get the ACTUAL open, high, low, close values?
The date works fine. It iisplays the actual value dynamically on mouse over.

The open, high, low, close show a value, - but a static one. And a false value as well.
See the screenshot to see at one glance, what works and what not.

Code: Pascal  [Select][+][-]
1.
2. var ser: TOpenHighLowCloseSeries;
3.     punkt: Integer;
4.     o, h, l, c: double;
5.     tmp: integer;  // aus Delpi
6.     s: String;
7.     d: double;
8.     dat: TDate;
9.
10. =============
11.
12.
13.   Memo_AusgabeKerze.Clear;
14.
15.   with TDatapointHintTool(ATool) do begin   // was das tut, weiß ich nicht genau. Es ist aus der Vorlage und vermutl. wichtig
16.    ser := ATool.Series as TOpenHighLowCloseSeries;
17.    punkt := PointIndex;
18.   end;
19.
20.  if ser <> nil then begin
21.    With Ser do begin
22.       o:=ser.YIndexOpen;
23.       H:=ser.YIndexHigh;
24.       L:=ser.YIndexLow;
25.       c:=ser.YIndexClose;
26.       dat:=ser.GetXValue(punkt);
27.
28.       s:=Zeit.FORMATIERE_DATUM_nur_Wochentag_KURZ(Dat);
29.       s := DateToStr(Dat) + ', ' + s + #13#10; // + #13#10;
30.       s := s + 'open=' + FloatToStrF(O,ffFixed,4,4) + #13#10;
31.       s := s + 'high=' + FloatToStrF(h,ffFixed,4,4) + #13#10;
32.       s := s + 'low=' + FloatToStrF(L,ffFixed,4,4) + #13#10;
33.       s := s + 'close=' + FloatToStrF(C,ffFixed,4,4) + #13#10;
34.
36.                 end;
37.         end;

question:
What do I have to change, that the values of the open, high, low, close is displayed the same way as the date-value?
Thanks.

#### wp

• Hero Member
• Posts: 10678
##### Re: DataPointHintTool - TOpenHighLowCloseSeries
« Reply #1 on: January 27, 2023, 06:18:36 pm »
The variables O, H, L, C that you extract from the series (O := ser.YIndexOpen, etc.) are the indices at which the Open/High/Low/Close values can be found in the series data point record, but not the Open/High/Low/Close values themselves. Use the ser.YValues[pointIndex, yindex] to extract the data value of a series with multiple y values:

Code: Pascal  [Select][+][-]
1. if ser <> nil then begin
2.    With Ser do begin
3.       O:=YValues[punkt, YIndexOpen];    // Be careful to use the plural here, YValues rather than YValue, because we have multiple y values
4.       H:=YValues[punkt, YIndexHigh];
5.       L:=YValues[punkt, YIndexLow];
6.       C:=YValues[punkt, YIndexClose];
7.       dat:=XValue[punkt];  // or: dat := ser.GetXValue(punkt);  // Singular here, because we have only 1 x value

#### Nicole

• Hero Member
• Posts: 744
##### [solved] Re: DataPointHintTool - TOpenHighLowCloseSeries
« Reply #2 on: January 27, 2023, 06:30:21 pm »
THIS is the syntax!
Thank you so much. Now it works.

And thank you for the hint with the s.
I copy it into my code. May save me some hours after a year will have passed by, when I will have forgotten all about this topic.