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
Marks centered in the bar
Hi Milton,
you can use similar code to the following ( it move the marks to the center of Stacked Bars ).
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;
Pep Jorge
http://support.steema.com
http://support.steema.com
Here is my Builcer C++ version...
I'm having a problem with assigning the MarkPos object to the BarSeries->Marks->Positions... Can you help?
Regards John
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
Hi,
Yes, sorry I mistake me , it should be :
BarSeries->Marks->Positions->Position = MarkPos;
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;
Pep Jorge
http://support.steema.com
http://support.steema.com