Page 1 of 1

Line series and empty invisible values

Posted: Wed Oct 10, 2018 9:23 am
by 16482785
Hello,

I am using TeeChart Pro with Delphi Tokyo. I want to draw a fastLine serie with empty values.

I tried to add empty values with the AddNullXY method but I have vertical lines to 0:
AddNullXY.jpg
AddNullXY.jpg (101.5 KiB) Viewed 279 times

I tried to add empty values with the AddXY(0,0) method but I have diagonal lines connecting last and first visible values:
AddNullX0Y0.jpg
AddNullX0Y0.jpg (88.96 KiB) Viewed 279 times

I thought I found a way to have what I want using multiple series: I create an new serie when previous values is empty:
MultipleSeries.jpg
MultipleSeries.jpg (64.21 KiB) Viewed 279 times
The rendering is OK but I have a TCurorTool object (red vertical line) that shows serie values. When using muItiple series, I can't use TCurorTool OnChange event :x

My issue is: how can I get last display with one serie or how can I get serie values with TCurorTool ?

Thanks for your support.

Julien

Re: Line series and empty invisible values

Posted: Mon Oct 15, 2018 9:20 am
by yeray
Hello,

I see the fix for #2006 broke this. I've added it to the public tracker (#2112). As you can see, I've already fixed it.

If you still need to use several TFastLineSeries for each "segment" you could use a TCursorTool and use the InterpolateLineSeries function from here as shown below:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
    tmpX, tmpY: Double;
begin
  Caption:=TeeMsg_Version;

  Chart1.Legend.Hide;
  Chart1.View3D:=False;

  Chart1.AddSeries(TFastLineSeries);
  tmpX:=0;
  tmpY:=100+random*50;

  for i:=0 to 99 do
    if (i mod 20 = 0) then
      Chart1.AddSeries(TFastLineSeries)
    else
    begin
      Chart1[Chart1.SeriesCount-1].AddXY(tmpX, tmpY);
      tmpX:=tmpX+1;
      tmpY:=tmpY+random*10-5;
    end;

  with Chart1.Tools.Add(TCursorTool) as TCursorTool do
  begin
    Style:=cssVertical;
    FollowMouse:=True;
    OnChange:=CursorChange;
  end;
end;

procedure TForm1.CursorChange(Sender:TCursorTool;x,y:Integer;Const XValue,YValue:Double;
                              Series:TChartSeries;ValueIndex:Integer);
var i: Integer;
begin
  Caption:='Nothing';

  for i:=0 to Chart1.SeriesCount-1 do
    if ((XValue >= Chart1[i].XValues.MinValue) and (XValue <= Chart1[i].XValues.MaxValue)) then
       Caption:=FormatFloat('#,##0.##', InterpolateLineSeries(Chart1[i], XValue));

end;

function TForm1.InterpolateLineSeries(Series: TChartSeries;
  XValue: Double): Double;
begin
  result:=InterpolateLineSeries(Series,Series.FirstDisplayedIndex,Series.LastValueIndex,XValue);
end;

function TForm1.InterpolateLineSeries(Series: TChartSeries;
  FirstIndex, LastIndex: Integer; XValue: Double): Double;
var
  Index: Integer;
  dx,dy: Double;
begin
  for Index:=FirstIndex to LastIndex do
    if Series.XValues.Value[Index]>XValue then break;

  //safeguard
  if (Index<1) then Index:=1
  else if (Index>=Series.Count) then Index:=Series.Count-1;

  // y=(y2-y1)/(x2-x1)*(x-x1)+y1
  dx:=Series.XValues.Value[Index] - Series.XValues.Value[Index-1];
  dy:=Series.YValues.Value[Index] - Series.YValues.Value[Index-1];

  if (dx<>0) then
    result:=dy*(XValue - Series.XValues.Value[Index-1])/dx + Series.YValues.Value[Index-1]
  else result:=0;
end;

Re: Line series and empty invisible values

Posted: Tue Oct 16, 2018 7:59 am
by 16482785
Hello Yeray,

Thanks for your support.

I tried your solution, it barely works. I still have an issue when displaying datas (dates) in abscissis.

In the picture above, I have one serie and I display dates in abscissis --> everything is OK
AddXYDate.jpg
AddXYDate.jpg (114.82 KiB) Viewed 258 times
In the picture above, I use your solution, I have many series and I display dates in abscissis --> labels overlap
AddXYDateFilter.jpg
AddXYDateFilter.jpg (74.3 KiB) Viewed 258 times
I dont' find a way to have a correct display. Do you have an idea ?

Kind Regards,

Julien

Re: Line series and empty invisible values

Posted: Wed Oct 17, 2018 8:55 am
by yeray
Hello Julien,

If you are converting the dates to strings and passing it to the series as labels when adding the points... ie:

Code: Select all

  label:=FormatDateTime('dd/mm/yyyy hh:nn:ss', date);
  series.AddXY(xValue, yValue, label);
In that case I'd suggest you to use the date a xValue. Ie:

Code: Select all

  series.AddXY(date, yValue);
You could also try changing the bottom axis labelStyle to talValue:

Code: Select all

  Chart1.Axes.Bottom.LabelsStyle:=talValue;

Re: Line series and empty invisible values

Posted: Wed Oct 17, 2018 2:26 pm
by 16482785
Hello Yeray,

Thanks you for the tip but I already tried this and I had some weird values :? I think my date value is converted to double value.
AddDateY.jpg
AddDateY.jpg (7.78 KiB) Viewed 238 times

Regards,

Julien

Re: Line series and empty invisible values

Posted: Tue Oct 23, 2018 6:53 am
by yeray
Hello,

The axis treats the values as DateTimes when it has a ValueList assigned to it with DateTime property set to True. Ie:

Code: Select all

  Chart1[0].XValues.DateTime:=true;

Re: Line series and empty invisible values

Posted: Tue Oct 23, 2018 7:24 am
by 16482785
Hello,
It works so fine. Teechart is a powerfull tool !!!
Thanks you