Page 1 of 1

MinYValue and MaxYValue to get X value as date/time?

Posted: Fri Nov 04, 2005 5:10 pm
by 9238735
I have a chart with values in the Y axis and date/time on the X axis.

I currently display the Series.MinYValue and Series.MaxYValue but would like to also display date/time from the X axis that coresponds to the min and max.

Also is there a Series Average value available?

Steve...

Posted: Tue Nov 08, 2005 4:29 pm
by narcis
Hi Steve,

Yes, you can use something like:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  i, YMinIndex, YMaxIndex: Integer;
  avg: double;
begin
  Series1.FillSampleValues();

  YMinIndex:=0;
  YMaxIndex:=YMinIndex;
  Series1.XValues.DateTime := true;
  avg:=Series1.YValues[0];
  for i:=1 to Series1.Count-1 do
  begin
    if Series1.YValues[i]<Series1.YValues[YMinIndex] then YMinIndex:=i
    else if Series1.YValues[i]>Series1.YValues[YMaxIndex] then YMaxIndex:=i;

    avg:=avg+Series1.YValue[i]
  end;

  avg:=avg/Series1.Count;

  Chart1.Title.Text[0]:=DateTimeToStr(Series1.XValue[YMinIndex])+' , '+
          DateTimeToStr(Series1.XValue[YMaxIndex])+'. Average:'+
          FloatToStr(avg);
end;
Also is there a Series Average value available?
See "avg" variable output already added in the code before. You have to calculate this value manually.