2014.11.140409
In the attached demo, I have code that use to work (I believe Steema support provided similar code) to draw selected labels on the bottom axis in red. This one should draw every other label in red. It doesn't work in the latest version.
How should this be coded?
Ed Dressel
Drawing bottom axis label in red
-
- Advanced
- Posts: 228
- Joined: Tue Aug 28, 2007 12:00 am
- Location: Oregon, USA
Drawing bottom axis label in red
- Attachments
-
- Draw Axis Label.zip
- (2.2 KiB) Downloaded 578 times
Re: Drawing bottom axis label in red
Hi Ed,
Instead of modifying the Canvas Font, you could modify the Bottom Axis LabelsFont in the OnDrawLabel event, making sure you also handle the "else" situation setting the default properties to the LabelsFont. Ie:
As an alternative, the latest TeeChart versions allow you yo to directly set the LabelsList in your Bottom Axis, instead of having to use the OnDrawLabel event. Ie:
Instead of modifying the Canvas Font, you could modify the Bottom Axis LabelsFont in the OnDrawLabel event, making sure you also handle the "else" situation setting the default properties to the LabelsFont. Ie:
Code: Select all
if (lIdx > -1) and (FDrawRedIndexes.IndexOf(TObject(lIdx)) > -1) then
begin
{lChart.Canvas.Font.Color := clRed;
lChart.Canvas.Font.Style := [fsBold];}
lChart.Axes.Bottom.LabelsFont.Color:=clRed;
lChart.Axes.Bottom.LabelsFont.Style:=[fsBold];
end
else
begin
lChart.Axes.Bottom.LabelsFont.Color:=clBlack;
lChart.Axes.Bottom.LabelsFont.Style:=[];
end;
Code: Select all
constructor TForm1.Create(aOwner: TComponent);
var
lValue: Double;
I, J: Integer;
lIdx: Integer;
aX: Integer;
lCalcXPos: Integer;
lMinOffBy: Integer;
lOffBy: Integer;
lSrs: TChartSeries;
begin
inherited;
Caption := TeeMsg_Version;
FDrawRedIndexes := TList.Create;
SEries1.Clear;
lValue := 1000.0;
for I := 0 to 19 do
begin
Series1.Add(lValue);
lValue := lValue * 1.03;
if (I mod 2) = 0 then
FDrawRedIndexes.Add(TObject(I));
end;
//Chart1.BottomAxis.OnDrawLabel := ChartBottomAxisDrawLabel;
Chart1.Draw;
with Chart1.Axes.Bottom.Items do
begin
Automatic:=false;
for I := 0 to Count-1 do
begin
lSrs := Chart1.Series[0];
lIdx := -1;
aX := Item[I].LabelPos;
lMinOffBy := MaxInt;
for J := lSrs.Count - 1 downto 0 do
begin
lCalcXPos := lSrs.CalcXPos(J);
lOffBy := abs(aX - lCalcXPos);
if (lOffBy < lMinOffBy) then
begin
lIdx := J;
lMinOffBy := lOffBy;
end;
end;
if (lIdx > -1) and (FDrawRedIndexes.IndexOf(TObject(lIdx)) > -1) then
begin
Item[I].Format.Font.Color := clRed;
Item[I].Format.Font.Style := [fsBold];
end;
end;
end;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |