Page 1 of 1

Disconnected Self-Stacked Horizontal Bar or Line segments

Posted: Thu Mar 23, 2006 7:21 pm
by 9333098
I wish to display several horizontal bars or lines of different widths but same height at the same Y Value whose individual bar or line segments are disconnected from each other and can be individually colored. The will be more than one of the "series" of such groups of values.

For example, a bar or line would be drawn between the following X data values all having the same Y value of 1 : (Similar data sets would be drawn at Y=2 and Y=3, etc)

1.5 to 2.2
2.7 to 3.5
4.0 to 7.1

Nothing would be displayed between 2.2 and 2.7 or 3.5 to 4.0. I have not been able to come up with a way to use a bar series to accomplish this. It can be done with a line series using :

Series1.ColorEachPoint := true;
Series1 ColorEachLine := true;
Series1.LinePen.EndStyle := esFlat;
Series1.LinePen.Width := 4;

with Series1 do
begin
AddXY(2,1,'',clred);
AddXY(3,1,'',clred);

AddNullXY(3,1,'');

AddXY(3.5,1,'',cllime);
AddXY(4,1,'',cllime);

AddNullXY(4,1,'');

AddXY(5,1,'',clred);
AddXY(6,1,'',clred);
end;


Creating the line series at run time and setting its line pen end style gives Undeclared identifier error for esFlat :
(chart1.Series[0] as TLineSeries).LinePen.EndStyle := esFlat;

Posted: Fri Mar 24, 2006 9:49 am
by narcis
Hi SteveP,

It must be because you need to add TeCanvas unit to your form uses section. It works fine here including the unit and using:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AddSeries(TLineSeries.Create(self));

  with (Chart1[0] as TLineSeries) do
  begin
    ColorEachPoint := true;
    ColorEachLine := true;
    LinePen.EndStyle := esFlat;
    LinePen.Width := 4;

    AddXY(2,1,'',clred);
    AddXY(3,1,'',clred);

    AddNullXY(3,1,'');

    AddXY(3.5,1,'',cllime);
    AddXY(4,1,'',cllime);

    AddNullXY(4,1,'');

    AddXY(5,1,'',clred);
    AddXY(6,1,'',clred);
  end;
end;