Page 1 of 1

Looking for an example for THorizLine w oscilloscope curve

Posted: Tue Nov 28, 2017 12:45 pm
by 10045871
Hello,

A FastLineSeries can run from the left to the righ and inversely in the manner of an oscilloscope. I use the
following commands for a curve which runs from the left to the right:

Code: Select all

 
with MyFastLineSeries do begin
    tmpTch:=XValues[1]-XValues[0];
    if (Count>100) then repeat Delete(count-1) until count<= 100;
    AddXY(XValues.First-tmpTch,ValueTobePlotted,'',clBlack)
end;
But I would like to make it running from the top to the bottom of the Chart in the manner of a data recorder. I tried to use the THorizLineSeries in the same manner:

Code: Select all

with MyHorizLineSeries do begin
    tmpTch:=YValues[1]-YValues[0];  // << Please note that I have exchanged the place of X and Y
    if (Count>100) then repeat Delete(count-1) until count<= 100;
    AddXY(ValueTobePlotted,YValues.First-tmpTch,'',clBlack) // << Please note that I have exchanged the place of X and Y
end;
However, this doesn't work.

What's wrong? Could you advise how I can get the right code for making the curve running from the top to the bottom of the graphic ?

Thank you in advance.
Pierre
Sciensoria

Re: Looking for an example for THorizLine w oscilloscope curve

Posted: Tue Nov 28, 2017 2:13 pm
by yeray
Hello,

I guess this code is fired inside some to that sets ValueTobePlotted variable, but without knowing exactly how I'm afraid I can't reproduce the problem here.
This simple example seems to work fine for me here:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1.View3D:=False;
  Chart1.Legend.Visible:=False;

  with Chart1.AddSeries(THorizLineSeries) do
  begin
    AddXY(100+random*50,0,'',clBlack);
    for i:=1 to 99 do
      AddXY(XValues[i-1]+random*10-5,i,'',clBlack);
  end;
end;

Re: Looking for an example for THorizLine w oscilloscope curve

Posted: Tue Nov 28, 2017 10:01 pm
by 10045871
Dear Yeray,

Thank you very much for your prompt reply.

I attache my test project here. It contains 2 charts (1 and 2). On the 1st chart, I display a sinus using a TFastLineSeries at the start and click on the button underneath to make it running. This works fine. On the 2nd chart, I also display a sinus vertically with a THorizLineSeries at the start and try to make it running as with the 1st chart. The both methods are same.

Unfortunately, the sinus on the 2nd chart doesn't move at all. I wonder if there are any other settings to do before elsewhere.

The source code seems to be too big to be attached here, but I can send it to you by another means.

Thank you in advance for your support.

Code: Select all

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, VclTee.TeeGDIPlus, Vcl.StdCtrls,
  Vcl.Buttons, VCLTee.TeEngine, VCLTee.Series, Vcl.ExtCtrls, VCLTee.TeeProcs,
  VCLTee.Chart;

type
  TForm1 = class(TForm)
    Chart1: TChart;
    BitBtn1: TBitBtn;
    CheckBox1: TCheckBox;
    Label1: TLabel;
    BitBtn2: TBitBtn;
    CheckBox2: TCheckBox;
    Label2: TLabel;
    Chart2: TChart;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Series1: TFastLineSeries; Series2: THorizLineSeries;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
var i,j,k: integer; tmp: double;
begin
  i:= 0;
  repeat
    with Series1 do begin
      tmp:= Xvalues[1]-Xvalues[0];
      AddXY(XValues.First-tmp,sin(2*pi/100*i),'',clBlack);
      if count>200 then delete(count-1);
    end;
    inc(i); Label1.Caption:= IntToStr(i);
    if i>2000 then i:= 0;
    Application.ProcessMessages;
  until checkbox1.Checked=false;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
var i,j,k: integer; tmp: double;
begin
  i:= 0;
  repeat
    with Series2 do begin
      tmp:= Yvalues[1]-Yvalues[0];
      AddXY(sin(2*pi/100*i),YValues.First-tmp,'',clBlack);
      if count>200 then delete(count-1);
    end;
    inc(i); Label2.Caption:= IntToStr(i);
    if i>200 then i:= 0;
    Application.ProcessMessages;
  until checkbox2.Checked=false;
end;

procedure TForm1.FormCreate(Sender: TObject);
var i: integer;
begin
  Series1:= TFastLineSeries.Create(nil);
  //Series1.FillSampleValues(20);
  for i:= 0 to 200 do Series1.AddXY(i,sin(2*pi/100*i),'',clRed);
  Chart1.AddSeries(Series1);
  Series2:= THorizLineSeries.Create(nil);
  //Series2.FillSampleValues(20);
  for i:= 0 to 200 do Series2.AddXY(sin(2*pi/100*i),i,'',clRed);
  Chart2.AddSeries(Series2);
end;

end.

Re: Looking for an example for THorizLine w oscilloscope curve

Posted: Wed Nov 29, 2017 12:07 pm
by yeray
Hello,

Try sorting the YValues after adding values to the THorizLineSeries. Ie:

Code: Select all

procedure TForm1.BitBtn2Click(Sender: TObject);
var i,j,k: integer; tmp: double;
begin
  i:= 0;
  repeat
    with Series2 do begin
      tmp:= Yvalues[1]-Yvalues[0];
      AddXY(sin(2*pi/100*i),YValues.First-tmp,'',clBlack);
      YValues.Sort;
      if count>200 then delete(count-1);
    end;
    inc(i); Label2.Caption:= IntToStr(i);
    if i>200 then i:= 0;
    Application.ProcessMessages;
  until checkbox2.Checked=false;
end;

Re: Looking for an example for THorizLine w oscilloscope curve

Posted: Thu Dec 07, 2017 1:50 pm
by 10045871
Thank you Yeray. I can confirm that this works.
However, I don't know why we have to do a sorting for the Yvalues for the THorizLineSeries while it is not necessary to do the same for a classic TFastLineSeries. In addition, I wonder if this slows down the plot rate.

Patrick
Sciensoria

Re: Looking for an example for THorizLine w oscilloscope curve

Posted: Mon Dec 11, 2017 9:19 am
by yeray
Hello Patrick,
Sciensoria wrote:I don't know why we have to do a sorting for the Yvalues for the THorizLineSeries while it is not necessary to do the same for a classic TFastLineSeries
This happens because the AddXY method, for the THorizLineSeries is adding the value at the end of the X and Y arrays, so removing the last point is removing the point just entered.
I've added it to the public tracker #1958.
Sciensoria wrote:In addition, I wonder if this slows down the plot rate.
I've added a TRepaintMonitor tool to check it and I don't see a decrease on the FPS after adding that Sort call.

Re: Looking for an example for THorizLine w oscilloscope curve

Posted: Mon Dec 11, 2017 9:27 am
by 10045871
Thank you Yeray. You have explained all my questions.

Patrick

Re: Looking for an example for THorizLine w oscilloscope curve

Posted: Mon Dec 11, 2017 9:41 am
by yeray
Hello Patrick,
Yeray wrote: I've added it to the public tracker #1958.
I've just fixed it.