AxisValuesFormat has no effect

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Doug
Newbie
Newbie
Posts: 7
Joined: Tue Apr 13, 2004 4:00 am

AxisValuesFormat has no effect

Post by Doug » Tue Mar 02, 2010 6:47 pm

Hello,

I am trying to format the x-axis labels in a simple line chart as '0.00' to produce for example 1.23 or 6767.22. Problem is the BottomAxis.AxisValuesFormat does not seem to be doing anything for this particular chart. It's strange because it works for other charts that I've created. The numbers on the x-axis are very long, e.g. 2009.0138888889 - do they have to be truncated? I thought the AxisValuesFormat would remove the need for that. I've tried '0.##', '#.##', everything. Also tried setting the BottomAxis.Increment to 0.01.

I've attached a screen cap to demonstrate.
Axis format problem.jpg
Axis format problem.jpg (76.48 KiB) Viewed 5492 times
Many thanks, Doug

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: AxisValuesFormat has no effect

Post by Yeray » Wed Mar 03, 2010 4:01 pm

Hi Doug,

Is it possible that you've entered your values with label and this label is what is shown in the bottom axis?
In that case, note that you are trying to format a string, not a double. To format it you need to convert your labels to a float, and then format them. And to do this you should use OnGetAxisLabel event. Here is an example:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;

  with Chart1.AddSeries(TBarSeries.Create(self)) do
  begin
    FillSampleValues(200);
    Marks.Visible:=false;

    for i:=0 to Count-1 do
      Labels.Labels[i]:=FloatToStr(Pi*(i+1));
  end;

  Chart1.Axes.Bottom.LabelsAngle:=90;
end;

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis;
  Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
begin
  if (Sender = Chart1.Axes.Bottom) then
  begin
    LabelText:=FormatFloat('#.##',StrToFloat(LabelText));
  end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Doug
Newbie
Newbie
Posts: 7
Joined: Tue Apr 13, 2004 4:00 am

Re: AxisValuesFormat has no effect

Post by Doug » Wed Mar 03, 2010 7:17 pm

That solved it Yeray, once again thank-you!

Post Reply