Default mark position of stack bar charts

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Frank
Newbie
Newbie
Posts: 4
Joined: Fri Dec 16, 2005 12:00 am

Default mark position of stack bar charts

Post by Frank » Tue May 23, 2006 5:12 am

Hey guys,

I 'm using teechart 7 vcl for my project. I noticed that on stack bar charts I made, if i have multiple series, the marks of previous series are always overlapped and hidden by the bars of next series. Any thoughts on that?

thanks!

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

Post by Narcís » Tue May 23, 2006 7:31 am

Hi Frank,

You can reposition the marks by doing something like this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  for i:=0 to Chart1.SeriesCount-1 do
  begin
    Chart1[i].FillSampleValues();
    Chart1[i].Marks.ArrowLength:=-30;
    Chart1[i].Marks.Arrow.Visible:=false;
  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

Frank
Newbie
Newbie
Posts: 4
Joined: Fri Dec 16, 2005 12:00 am

Post by Frank » Tue May 23, 2006 3:54 pm

Thank you for the quick reply, Narcis.

However, i see another issue with stack bar charts. What if i want to display the marks in the middle of bars? Do i have to find out the length of bar first and then specifiy the arrowlength base on that? If that's the case i guess i need to specify different arrowlengths for marks that in the same series, am i right?

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 May 24, 2006 7:52 am

Hi Frank,

Yes, or you can also use custom marks as shown here:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
  APosition:TSeriesMarkPosition;
begin
  Series1.FillSampleValues();
  Chart1.Draw();

  APosition:=TSeriesMarkPosition.Create;
  try
    for i:=0 to Series1.Count-1 do
    begin
      APosition.Custom:=True;
      APosition.LeftTop.X:=Series1.Marks.Positions[i].LeftTop.X;
      APosition.LeftTop.Y:=Series1.Marks.Positions[i].LeftTop.Y-35;
      Series1.Marks.Positions[i]:=APosition;
    end;
  finally
      APosition.Free;
  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

Frank
Newbie
Newbie
Posts: 4
Joined: Fri Dec 16, 2005 12:00 am

Post by Frank » Thu May 25, 2006 8:33 pm

Hi Narcis,

Is there any easy way that i can tell the lengths of bars of each value point in each series? It seems like i need to find out those to be able to specify the arrowlengths of marks.

Any thoughts?

thanks a bunch.

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Tue May 30, 2006 2:44 pm

Hi Frank,

yes, you can check where a specified point (bar) starts and ends using the code below. This example shows how to position Marks in the middle of each stacked Bar Series :

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
series1.FillSampleValues(5);
Series2.FillSampleValues(5);
Series3.FillSampleValues(5);
end;


procedure TForm1.PositionChartMarks(BarSeries: TBarSeries);
var
  i: integer;
  YPos: integer;
  BarTop: integer;
  BarBottom: integer;
  XPos: integer;
  MarkPos: TSeriesMarkPosition;
begin
  MarkPos := TSeriesMarkPosition.Create;
  try
    for i := 0 to BarSeries.Count - 1 do begin
      // just an example, you can do further customization here
      MarkPos.Width := BarSeries.BarWidth;
      MarkPos.Height := 16;

      BarTop := BarSeries.CalcYPos(i); // get y screen pixel coordinate
      BarBottom := BarSeries.CalcYPosValue(BarSeries.PointOrigin(i,false));

      YPos := (BarTop + BarBottom - MarkPos.Height) div 2;
      // Make sure that the value isn't painted below the X Axis
      if YPos > (BarSeries.GetHorizAxis.PosAxis - (MarkPos.Height)) then begin
        YPos := BarSeries.GetHorizAxis.PosAxis - (MarkPos.Height);
      end;
      XPos := BarSeries.CalcXPos(i);

      MarkPos.Custom := True;
      MarkPos.LeftTop.X := XPos;
      MarkPos.LeftTop.Y := YPos;

      BarSeries.Marks.Positions[i] := MarkPos;
    end;
  finally
    MarkPos.Free;
  end;
  BarSeries.Repaint;
end;


procedure TForm1.Series1BeforeDrawValues(Sender: TObject);
begin
  PositionChartMarks(Sender as TBarSeries);
end;

end.

Frank
Newbie
Newbie
Posts: 4
Joined: Fri Dec 16, 2005 12:00 am

Post by Frank » Tue May 30, 2006 7:33 pm

Cool, this is exactly what i 'm looking for. Thanks Pep!

Post Reply