Page 1 of 1

Breaking TLineSeries

Posted: Thu Sep 15, 2005 4:06 pm
by 9232125
I have to draw a TLineSeries breaking it in some points.
For example, points 1 to 10 must be connected, and also points 11 to 20, but point 10 and 11 must be not connected.
Is it possible?

Thanks

Best Regards

FM

Posted: Fri Sep 16, 2005 7:48 am
by narcis
Hi FM,

Yes, this is possible adding null values to the series:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Randomize;

  for i:=0 to 20 do
    if i=11 then Series1.AddNull('')
    else Series1.Add(random);
end;

Posted: Sun Sep 18, 2005 9:29 am
by 9232125
Hi Narcis,
if I use Series.AddNull for point 11, like in your example, I can't see this point on the graph.
Line breaks on point 10 and restarts on point 12; instead I need to see also point 11, and the line has to break on point 10 and to restart just on point 11.

Best regards

FM

Posted: Mon Sep 19, 2005 10:58 am
by narcis
Hi FM,

To achieve what you request you have 2 options:

1) Using a TLineSeries and adding an additional null point between the two points where the gap has to be:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Randomize;

  for i:=0 to 20 do
  begin
    if i=11 then Series1.AddNullXY(i-0.5,random);
    Series1.AddXY(i,random);
  end;
end;
2) Using a TPointSeries and TChart's OnAfterDraw event to custom draw a line between the points you want need and not drawing the line for the null point gap:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues();
  Series1.Pointer.Visible:=false;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var
  Index: Integer;
begin
  With Chart1.Canvas, Series1 do
    for Index:=1 to Count-1 do
      if Index <> 11 then
      begin
        MoveTo(CalcXPos(Index-1),CalcYPos(Index-1));
        LineTo(CalcXPos(Index),CalcYPos(Index));
      end;
end;