Page 1 of 1
Default mark position of stack bar charts
Posted: Tue May 23, 2006 5:12 am
by 9344573
Hey guys,
I 'm using teechart 7 vcl for my project. I noticed that on stack bar charts I made, if i have multiple series, the marks of previous series are always overlapped and hidden by the bars of next series. Any thoughts on that?
thanks!
Posted: Tue May 23, 2006 7:31 am
by narcis
Hi Frank,
You can reposition the marks by doing something like this:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
for i:=0 to Chart1.SeriesCount-1 do
begin
Chart1[i].FillSampleValues();
Chart1[i].Marks.ArrowLength:=-30;
Chart1[i].Marks.Arrow.Visible:=false;
end;
end;
Posted: Tue May 23, 2006 3:54 pm
by 9344573
Thank you for the quick reply, Narcis.
However, i see another issue with stack bar charts. What if i want to display the marks in the middle of bars? Do i have to find out the length of bar first and then specifiy the arrowlength base on that? If that's the case i guess i need to specify different arrowlengths for marks that in the same series, am i right?
Posted: Wed May 24, 2006 7:52 am
by narcis
Hi Frank,
Yes, or you can also use custom marks as shown here:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
APosition:TSeriesMarkPosition;
begin
Series1.FillSampleValues();
Chart1.Draw();
APosition:=TSeriesMarkPosition.Create;
try
for i:=0 to Series1.Count-1 do
begin
APosition.Custom:=True;
APosition.LeftTop.X:=Series1.Marks.Positions[i].LeftTop.X;
APosition.LeftTop.Y:=Series1.Marks.Positions[i].LeftTop.Y-35;
Series1.Marks.Positions[i]:=APosition;
end;
finally
APosition.Free;
end;
end;
Posted: Thu May 25, 2006 8:33 pm
by 9344573
Hi Narcis,
Is there any easy way that i can tell the lengths of bars of each value point in each series? It seems like i need to find out those to be able to specify the arrowlengths of marks.
Any thoughts?
thanks a bunch.
Posted: Tue May 30, 2006 2:44 pm
by Pep
Hi Frank,
yes, you can check where a specified point (bar) starts and ends using the code below. This example shows how to position Marks in the middle of each stacked Bar Series :
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;
end.
Posted: Tue May 30, 2006 7:33 pm
by 9344573
Cool, this is exactly what i 'm looking for. Thanks Pep!