0
votes

I need to be able to format the X Axis labels on a TeeChart Standard 2012 chart. I’m handling the GetAxisLabel event, but the ValueIndex is always -1.

I found this bit of documentation:

Axis Labels are Values. In this case, the Series parameter will be nil, and the ValueIndex will be -1.

Axis Labels are Series points. The Series parameter will be a valid TChartSeries, and the ValueIndex will be the current Series point position.

The problem is that I can find no way to set the Axis Labels to series points.

Can someone help me out?

1

1 Answers

0
votes

You need to set LabelStyle to be:

  Chart1.Axes.Bottom.LabelStyle:=talPointValue;

or

  Chart1.Axes.Bottom.LabelStyle:=talText;

in your chart. Then you'll be able to do something like this:

procedure TForm2.Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
  ValueIndex: Integer; var LabelText: string);
begin
  if ((Series <> nil) and (ValueIndex <> -1)) then
  begin
    LabelText:=FormatFloat('#.00', Series.XValue[ValueIndex]);
  end;
end;

However, it's much easier to achieve what the method above does using AxisValuesFormat property:

  Chart1.Axes.Bottom.AxisValuesFormat:='#.00';