TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
-
myghetto
- Newbie
- Posts: 27
- Joined: Thu Oct 05, 2006 12:00 am
Post
by myghetto » Sun Nov 25, 2007 7:48 am
Hi,
I would like to find the maximum/minimum point in a line series within the stated range. For example, if there are 818 samples in my line and I would only like to find the maximum in the first 409 samples, how do I do it? Ive tried:
or
Problem with them is they find the whole line series. Please help. Thank you
David[/code]
-
Yeray
- Site Admin
- Posts: 9613
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Mon Nov 26, 2007 9:39 am
Hi mygetho,
You are right. MinYValue and MaxYValue return the minimum and maximum values of the entire series respectively. If you want to calculate the min and max for an interval, you have to calculate it manually creating your own functions.
One solution could be the following:
Code: Select all
function TForm1.Max(line: TLineSeries; indexfrom: Integer; indexto: Integer): Integer;
var i: Integer;
begin
result := -1;
if (((line.Count-1) >= indexfrom) and ((line.Count-1) >= indexto) and (indexfrom <= indexto)) then
begin
result := indexfrom;
for i := indexfrom to indexto do
begin
if line.YValue[i] > line.YValue[result] then
result := i;
end;
end;
end;
function TForm1.Min(line: TLineSeries; indexfrom, indexto: Integer): Integer;
var i: Integer;
begin
result := -1;
if (((line.Count-1) >= indexfrom) and ((line.Count-1) >= indexto) and (indexfrom <= indexto)) then
begin
result := indexfrom;
for i := indexfrom to indexto do
begin
if line.YValue[i] < line.YValue[result] then
result := i;
end;
end;
end;
In this example, we return the index of the point we've found.
-
myghetto
- Newbie
- Posts: 27
- Joined: Thu Oct 05, 2006 12:00 am
Post
by myghetto » Wed Nov 28, 2007 5:27 am
Hi,
I have tried your code and it works but the problem I am having now is that my line series has points that increase and decrease like a roller coaster so basically it will keep detecting the min or max up til the end as long as the if statement is true. Is there a way to do it so that it will find the absolute max value or min value within a specified range like the MinYValue or MaxYValue. Thanks.
David
-
Yeray
- Site Admin
- Posts: 9613
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Wed Nov 28, 2007 10:02 am
Hi mygetho,
If I understand well, you want a function which, with a minimum and a maximum Y values given, gives the minimum point of the series (and another one that gives the maximum).
In other words, as you can see in the image, you set an interval of Y values and you search for the maximum and minimum of this interval.
Click on the image to enlarge.
-
Yeray
- Site Admin
- Posts: 9613
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Wed Nov 28, 2007 10:33 am
Hi mygetho,
Here there are two functions that will achieve what I understood:
Code: Select all
function TForm1.MaxBetween(line: TLineSeries; MinYValue, MaxYValue: Double): Integer;
var i: Integer;
begin
result := -1;
if (MinYValue <= MaxYValue) then
for i := 0 to line.Count-1 do
if (line.YValue[i] <= MaxYValue) and (line.YValue[i] >= MinYValue) then
if (result = -1) then
result := i
else
if (line.YValue[i] > line.YValue[result]) then
result := i;
end;
function TForm1.MinBetween(line: TLineSeries; MinYValue, MaxYValue: Double): Integer;
var i: Integer;
begin
result := -1;
if (MinYValue <= MaxYValue) then
for i := 0 to line.Count-1 do
if (line.YValue[i] <= MaxYValue) and (line.YValue[i] >= MinYValue) then
if (result = -1) then
result := i
else
if (line.YValue[i] < line.YValue[result]) then
result := i;
end;