TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
-
VideoTrack
- Newbie
- Posts: 17
- Joined: Thu Jan 04, 2018 12:00 am
Post
by VideoTrack » Tue Nov 13, 2018 1:47 pm
I have a stacked Horizontal Bar series.
I am using custom mark position to place the marks above the bar series. However, despite efforts, the text I want to display shows at the RHS of the bar. How can I show the value at the LHS of the bar?
The values I display are the actual start positions of the bar, so accordingly I want to show them on the chart where each bar segment starts.
MarksLocation := mlStart did not seem to change anything.
- 2018-11-14_00-30-55.jpg (34.42 KiB) Viewed 10126 times
Code: Select all
APosition:=TSeriesMarkPosition.Create;
try
for j := high(IDMRecords.PhaseRecs) downto 0 do
begin
for i:=0 to PhDataSeries[j].Count-1 do
if assigned(PhDataSeries[j].Marks.Positions[i]) then
begin
APosition.Custom:=True;
PhDataSeries[j].MarksLocation := mlCenter; // mlStart (?);
APosition.LeftTop.Y:=PhDataSeries[j].Marks.Positions[i].LeftTop.Y - 5;
APosition.LeftTop.X:=PhDataSeries[j].Marks.Positions[i].LeftTop.X - 30;
PhDataSeries[j].Marks.Positions[i]:=APosition;
end; {for i}
end; {for j}
finally
APosition.Free;
end;
Many thanks!
-
Yeray
- Site Admin
- Posts: 9617
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Thu Nov 15, 2018 10:05 am
Hello,
The MarksLocation property is thought to be used with the automatic positioning of the marks, not with the Custom positions you are using.
Ie:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
Chart1.Legend.Hide;
for i:=0 to 3 do
with Chart1.AddSeries(THorizBarSeries) as THorizBarSeries do
begin
FillSampleValues(3);
Marks.Transparent:=True;
MultiBar:=mbStacked;
MarksOnBar:=True;
MarksLocation:=mlStart;
end;
end;
- Project3_2018-11-15_10-41-55.png (14.77 KiB) Viewed 10116 times
If you want to have your marks at the start but above the bars, you can use the Custom positions as follows:
Code: Select all
procedure TForm1.Chart1BeforeDrawSeries(Sender: TObject);
var i, j: Integer;
APosition: TSeriesMarkPosition;
begin
APosition:=TSeriesMarkPosition.Create;
try
APosition.Custom:=True;
for i:=0 to Chart1.SeriesCount-1 do
begin
with Chart1[i] as THorizBarSeries do
begin
for j:=0 to Count-1 do
begin
APosition.LeftTop.Y:=CalcYPos(j) - 20;
if i=0 then
APosition.LeftTop.X:=Chart1.Axes.Bottom.IStartPos
else
APosition.LeftTop.X:=Chart1[i-1].CalcXPos(j);
Inc(APosition.LeftTop.X, Chart1.Canvas.TextWidth(ValueMarkText[j]) div 2);
Marks.Positions[j]:=APosition;
end;
end;
end;
finally
APosition.Free;
end;
end;
- Project3_2018-11-15_11-04-32.png (12.62 KiB) Viewed 10116 times
-
VideoTrack
- Newbie
- Posts: 17
- Joined: Thu Jan 04, 2018 12:00 am
Post
by VideoTrack » Sun Nov 18, 2018 12:57 pm
Many thanks for the support. I got it working OK using a derivative of your example.