Page 1 of 1

Get Y value without using mouse click

Posted: Fri Feb 16, 2007 4:53 am
by 9043243
Hi,

I have two series lines on the chart, one is real time line, the other is predicated line which is ploted shortly after the application startup, the real time line will be plotted each time when a data arriving. One thing I want to do is to plot another line called "residual",in order to calculat the residual, the application needs to know the Y value of predicated line at the time when application is ploting the real-time data point.

The question is how to get the Y value of the chart already plotted ? if I use click event, there is an example in user manual can help me out, but without using such event handler, how can I get a plotted line's Y value ? without using click ? Thanks in advance.

Daniel

Posted: Fri Feb 16, 2007 8:50 am
by yeray
Hi nileiqi,

If your real-time line and your predicated line share the same X values then your problem could be solved with some like following:
(Note that we added 3 series and a timer to the form in design time and also note that we calculate residual points by subtraction of RealTime from Predicated).

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
    PredicatedLine.FillSampleValues(100);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
   index: Integer;
   PredicatedLineValue: double;
   RealTimeLineValue: double;
begin
     index := RealTimeLine.Add(random*1000);

     if index < PredicatedLine.Count then
     begin
          PredicatedLineValue := PredicatedLine.YValue[index];
          RealTimeLineValue := RealTimeLine.YValue[index];
          ResidualLine.Add(PredicatedLineValue - RealTimeLineValue);
     end;
end;
But if real-time line and predicated line don't share the X values, the the problem will be solved in a more complicated way, but we'll suggest you a solution.

Posted: Tue Feb 20, 2007 4:42 am
by 9043243
Yeray,

Thanks for your help. I realize that you assume same index for both predicated and realtime line, that not suits my case. They both share same X values (date time), the difference is that predicated line contains whole year length data, index =1 represents the first data of year, eg 2007-01-01 00:05:00, while for realtime line, index=1 represents first receiving data after the program starts running, if program starts now, index=1 represents the data at 2007-02-20 15:30:00.

My request is when I plot realtime point at current datetime, how do I get the Y value of predicated line at this datetime ? (the X value is date time). Below is how do I plot the predicated line, it may help to understand my question, Thanks in advance.

Daniel

===============================================
My chart spans 24 hours and shifts left at certain time. the X values is date time axis. I plot predicated line in this way, simply create a big array to carry one-year data, then call following pseudo code:

For i:=1 to predicated_line.count
AddXY(predicated_line.datetime, predicated_line.value )

Then TeeChart looks after predicated line, when I change the time span or shift time range, the predicated line always be plotted properly.
===============================================

[/b]

Posted: Tue Feb 20, 2007 9:48 am
by yeray
Hi nileiqi,
if we undestand your problem it should be solved using locate function, something like following:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
     PredicatedLine.FillSampleValues(100);
     PredicatedLine.XValues.DateTime := True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
   index: Integer;
   PredicatedLineValue: double;
   RealTimeLineValue: double;
   i: Integer;
begin
     index := RealTimeLine.Add(random*1000);

     if index < PredicatedLine.Count then
     begin
          RealTimeLineValue := RealTimeLine.YValue[index];
          i := PredicatedLine.XValues.Locate(RealTimeLine.XValue[index]);
          PredicatedLineValue := PredicatedLine.YValue[i];

          ResidualLine.Add(PredicatedLineValue - RealTimeLineValue);
     end;
end;

Posted: Wed Feb 21, 2007 12:31 am
by 9043243
Hi, Yeray

I don't fully understand following code
i := PredicatedLine.XValues.Locate(RealTimeLine.XValue[index]);
it returns i:=-1, it looks like corresponding point index can not be found, I did call PredicateLine.AddXY() to add all predicated data point into series list, online help file seems not completed for function Locate(..). Thanks in adcance.

Daniel

Posted: Wed Feb 21, 2007 9:11 am
by yeray
Hi Daniel,
probably not all your XValues for RealTime have a corresponding XValue in PredicatedLine.
So you'll probably need to compare for each XValue if it has a corresponding XValue in PredicatedLine. But then there are two possibilities:

-Assuming for all XValues, if they have an image, they are exaclty identic; same day, minute and second:

Code: Select all

procedure TForm1.Timer1Timer(Sender: TObject);
var
   index: Integer;
   PredicatedLineValue: double;
   RealTimeLineValue: double;
   i: Integer;
begin
     index := RealTimeLine.Add(random*1000);

     if index < PredicatedLine.Count then
     begin
          RealTimeLineValue := RealTimeLine.YValue[index];

          for i := 0 to  PredicatedLine.Count-1 do
          begin
             if (PredicatedLine.XValue[i] = RealTimeLine.XValue[i]) then break;  // if values are equal for day, minute and second
          end;

          PredicatedLineValue := PredicatedLine.YValue[i];

          ResidualLine.Add(PredicatedLineValue - RealTimeLineValue);
     end;
end;

-Assuming for all XValues, if they have an image, they are in the same day:

Code: Select all

procedure TForm1.Timer1Timer(Sender: TObject);
var
   index: Integer;
   PredicatedLineValue: double;
   RealTimeLineValue: double;
   i: Integer;
begin
     index := RealTimeLine.Add(random*1000);

     if index < PredicatedLine.Count then
     begin
          RealTimeLineValue := RealTimeLine.YValue[index];

          for i := 0 to  PredicatedLine.Count-1 do
          begin
             if (Abs(PredicatedLine.XValue[i] - RealTimeLine.XValue[i]) < 1 ) then break;  // if values are equal in the same day
          end;

          PredicatedLineValue := PredicatedLine.YValue[i];

          ResidualLine.Add(PredicatedLineValue - RealTimeLineValue);
     end;
end;

Posted: Thu Mar 01, 2007 5:19 am
by 9043243
Yeray,

Thank you,I got it.

Kind regards

Daniel