Line chart with error bars

Ideas and wishes for TeeChart
Post Reply
vas
Newbie
Newbie
Posts: 20
Joined: Wed Oct 17, 2007 12:00 am

Line chart with error bars

Post by vas » Wed Dec 24, 2008 11:18 am

A line chart with error bars seems to be missing from the multitude of chart types available.

I want to show trends over time, and compare groups (three series), but I would like to inform the viewer of the underlying variation, which I can calculate.

Essentially, I want to Add (X, Y, Error, ... ) like a CustomErrorBar, but I want a line graph, not a bar graph.

Any way around this in the mean time?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Dec 24, 2008 11:58 am

Hi vas,

Ok, I've added your request to the wish-list to be considered for inclusion in future releases.

In the meantime you can hide the bars and custom draw the line like this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.Clear;
  Series1.FillSampleValues();
  Series1.BarPen.Visible:=false;
  Series1.BarBrush.Style:=bsClear;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var i ,x, y, tmp: Integer;
begin
  tmp:=Series1.BarWidth div 2;
  x:=Series1.CalcXPos(0) + tmp;
  y:=Series1.CalcYPos(0);

  Chart1.Canvas.Pen.Color:=clRed;
  Chart1.Canvas.Pen.Width:=2;
  Chart1.Canvas.MoveTo(x, y);

  for i:=1 to Series1.Count-1 do
  begin
    x:=Series1.CalcXPos(i) + tmp;
    y:=Series1.CalcYPos(i);
    Chart1.Canvas.LineTo(x, y);
    Chart1.Canvas.MoveTo(x, y);
  end;
end;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Dec 24, 2008 12:50 pm

Hi vas,

For completeness, for 3D series you can do this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.Clear;
  Series1.FillSampleValues();
  Series1.BarPen.Visible:=false;
  Series1.BarBrush.Style:=bsClear;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var i ,x, y, tmp: Integer;
begin
  tmp:=Series1.BarWidth div 2;
  x:=Series1.CalcXPos(0) + tmp;
  y:=Series1.CalcYPos(0);

  Chart1.Canvas.Pen.Color:=clRed;
  Chart1.Canvas.Pen.Width:=2;
  Chart1.Canvas.MoveTo3D(x, y, Series1.MiddleZ);

  for i:=1 to Series1.Count-1 do
  begin
    x:=Series1.CalcXPos(i) + tmp;
    y:=Series1.CalcYPos(i);
    Chart1.Canvas.LineTo3D(x, y, Series1.MiddleZ);
    Chart1.Canvas.MoveTo3D(x, y, Series1.MiddleZ);
  end;
end;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

vas
Newbie
Newbie
Posts: 20
Joined: Wed Oct 17, 2007 12:00 am

Thank you

Post by vas » Wed Dec 24, 2008 7:24 pm

Wow, instant service, works perfectly, and I learned new skills at the same time!

vas
Newbie
Newbie
Posts: 20
Joined: Wed Oct 17, 2007 12:00 am

Clipping?

Post by vas » Thu Dec 25, 2008 7:03 am

Almost - this works, except when the screen is scrolled, the lines are displayed outside of the ChartRect.

Oddly, the error bars are not, nor are any other TeeChart series components.

But this is a minor issue for me, but it probably needs to addressed when the new ErrorLine Series is released.

Thanks again.

Post Reply