Marks centered in the bar

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
mLapido
Newbie
Newbie
Posts: 24
Joined: Wed Mar 24, 2004 5:00 am
Location: Brasil
Contact:

Marks centered in the bar

Post by mLapido » Tue Oct 19, 2004 6:04 pm

Hi,

Is there a way to show the marks centered in a bar of a vertical or horizontal bar chart? If so, how do go about it?

Regards,
Milton Lapido

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

Post by Pep » Thu Oct 21, 2004 6:26 am

Hi Milton,

you can use similar code to the following ( it move the marks to the center of Stacked Bars ).

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;

AMS
Newbie
Newbie
Posts: 24
Joined: Wed Mar 31, 2004 5:00 am
Location: South Africa
Contact:

Post by AMS » Fri Oct 22, 2004 11:37 am

Here is my Builcer C++ version...
I'm having a problem with assigning the MarkPos object to the BarSeries->Marks->Positions... Can you help?

Code: Select all

void __fastcall TGraphFrame::PositionChartMarks(TBarSeries *Sender)
{
  int                 i;
  int                 YPos;
  int                 BarTop;
  int                 BarBottom;
  int                 XPos;
  TSeriesMarkPosition *MarkPos = new TSeriesMarkPosition;

  for( int i=0; i < Sender->Count(); i++ )
  {
    MarkPos->Width = Sender->BarWidth;
    MarkPos->Height = 16;

    // Gets the Y screen pixel coordinate
    BarTop = Sender->CalcYPos(i);
    BarBottom = Sender->CalcYPosValue(Sender->PointOrigin(i,false));

    YPos = (BarTop + BarBottom - MarkPos->Height) / 2;

    // Make sure that the value isn't painted below the X Axis
    if( YPos > (Sender->GetHorizAxis->PosAxis - (MarkPos->Height)) )
    {
      YPos = Sender->GetHorizAxis->PosAxis - (MarkPos->Height);
    }

    XPos = Sender->CalcXPos(i);

    MarkPos->Custom = true;
    MarkPos->LeftTop.x = XPos;
    MarkPos->LeftTop.y = YPos;

    // Problem here!!!
    //Sender->Marks->Positions[i] = MarkPos;

  }

  delete MarkPos;

  Sender->Repaint();

} // PositionChartMarks
Regards John

mLapido
Newbie
Newbie
Posts: 24
Joined: Wed Mar 24, 2004 5:00 am
Location: Brasil
Contact:

Post by mLapido » Fri Oct 22, 2004 1:38 pm

I also develop in C++ and that attribution converted to:

BarSeries->Marks->Positions->Position = MarkPos;


But I'm not sure it's right. I haven't quite got that routine to work yet...

Regards,
Milton Lapido

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

Post by Pep » Fri Oct 22, 2004 3:27 pm

Hi,
I'm having a problem with assigning the MarkPos object to the BarSeries->Marks->Positions... Can you help?

Yes, sorry I mistake me , it should be :
BarSeries->Marks->Positions->Position = MarkPos;

Post Reply