Marks within Bars

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
sm
Newbie
Newbie
Posts: 13
Joined: Wed Feb 02, 2005 5:00 am

Marks within Bars

Post by sm » Tue Apr 19, 2005 8:34 am

Situation: Chart with two series of kind TBarJoinSeries which are stacked 100%.

I want to display the value of each bar within the bar itself. Is that possible and how would I do this?

TeeChart is version 7.02 for Delphi 7.

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 Apr 19, 2005 8:51 am

Hi sm,

Yes, one easy way of doing that is setting marks arrowlength to a negative value like in the example below:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  Chart1.AddSeries(TBarJoinSeries.Create(self));
  Chart1.AddSeries(TBarJoinSeries.Create(self));

  for i:=0 to Chart1.SeriesCount-1 do
    With Chart1[i] do
    begin
      FillSampleValues();
      Marks.Arrow.Visible:=false;
      Marks.ArrowLength:=-50;
    end;

  (Chart1[0] as TBarJoinSeries).MultiBar:=mbStacked100;
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

sm
Newbie
Newbie
Posts: 13
Joined: Wed Feb 02, 2005 5:00 am

Post by sm » Tue Apr 19, 2005 9:33 am

narcis wrote:Hi sm,

Yes, one easy way of doing that is setting marks arrowlength to a negative value like in the example below:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  Chart1.AddSeries(TBarJoinSeries.Create(self));
  Chart1.AddSeries(TBarJoinSeries.Create(self));

  for i:=0 to Chart1.SeriesCount-1 do
    With Chart1[i] do
    begin
      FillSampleValues();
      Marks.Arrow.Visible:=false;
      Marks.ArrowLength:=-50;
    end;

  (Chart1[0] as TBarJoinSeries).MultiBar:=mbStacked100;
end;
Thanks! But I would still have to calculate the arrow length by myself if I I want to center the marks. Also a hardcoded value for ArrowLength would not work if the bars values can be very small (the mark would slip into another bar).

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 Apr 19, 2005 11:01 am

Hi sm,

Ok, you can play with series values positions in the chart, ChartRect settings, series marks positions, etc. Find an example below:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  Chart1.AddSeries(TBarJoinSeries.Create(self));
  Chart1.AddSeries(TBarJoinSeries.Create(self));

  (Chart1[0] as TBarJoinSeries).MultiBar:=mbStacked100;

  for i:=0 to Chart1.SeriesCount-1 do
    Chart1[i].FillSampleValues();

  Chart1.Draw;
  CustomSeriesMarks;
end;

procedure TForm1.CustomSeriesMarks;
var
  i,j: Integer;
  APosition:TSeriesMarkPosition;
begin

  APosition:=TSeriesMarkPosition.Create;
  try

    for j:=0 to Chart1.SeriesCount-1 do
      for i:=0 to Chart1[j].Count-1 do
      begin
        APosition.Custom:=True;
        APosition.LeftTop.X:=Chart1[j].Marks.Positions[i].LeftTop.X;

        if (j=0) then
          APosition.LeftTop.Y:=Chart1[j].CalcYPos(i) +
                            ((Chart1[j+1].CalcYPos(i) -
                              Chart1[j].CalcYPos(i)) div 2)
        else
          APosition.LeftTop.Y:=Chart1[j].CalcYPos(i) +
                            ((Chart1.ChartRect.Bottom -
                              Chart1[j].CalcYPos(i)) div 2);

        Chart1[j].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

Post Reply