Axes Values Format of ffGeneral FloatFormat

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
SteveP
Advanced
Posts: 132
Joined: Sun Sep 07, 2003 4:00 am

Axes Values Format of ffGeneral FloatFormat

Post by SteveP » Fri Jan 23, 2004 7:36 pm

Is there a way to have axis labels format use fixed format for values within a range around 1 and use scientific format when outside the range. Similar to Delphi's FloatToStrF function specifying ffGeneral for its TFloatFormat type. This so label values far from 1 (for example 34596783263.93457 or 0.000000008345345234) would take less space on the chart by using the Exponent to indicate how large the value is.

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Mon Jan 26, 2004 1:06 pm

Hi, Steve.

Yes, it can be done, but if will require some code. I'd first display all axis labels in standard (float) format and then in chart OnGetAxisLabel event reformat labels outside specificed range. Something like this (just an example to give you basic idea):

Code: Select all

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis;
  Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
var tmp: double;
begin
  if Sender = Chart1.Axes.Left then
  begin
    // if you use thousand separator, you'll have to remove it prior to calling StrToFloat
    tmp := StrToFloat(LabelText);
    if Abs(tmp)>1 then LabelText := FormatFloat('0.0E+00',tmp);
  end;
end;
Marjan Slatinek,
http://www.steema.com

Post Reply