Page 1 of 1
Custom marks positions for Horizontal bar charts
Posted: Tue Jan 18, 2005 2:41 pm
by 9336617
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
Posted: Mon Jan 24, 2005 5:22 pm
by 9336617
Did this go unnoticed, or is this being intentionally ignored????
Simple question.... there must be a simple reply...
regards,
Milton
Posted: Tue Jan 25, 2005 9:06 am
by Pep
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.