Custom marks positions for Horizontal bar charts

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:

Custom marks positions for Horizontal bar charts

Post by mLapido » Tue Jan 18, 2005 2:41 pm

hi,

I want to reposition the marks on a horizontal bar chart, I tried setting the "Marks.Positions" property of THorizBarSeries, but it caused a side effect, the chart resizes in an unexpected way, it gets proportionally smaller as we resize it to a smaller size. I mean it starts using less and less of the available area for drawing the chart.

Any Ideas?

regards,
Milton

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

Post by mLapido » Mon Jan 24, 2005 5:22 pm

Did this go unnoticed, or is this being intentionally ignored????

Simple question.... there must be a simple reply...

regards,
Milton

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

Post by Pep » Tue Jan 25, 2005 9:06 am

Hi Milton,

sorry for delay !.. a simple example to which reposition the Marks could be :

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;
It center the Marks for a Stacked Bar Chart.

Post Reply