Page 1 of 1

AxisValuesFormat has no effect

Posted: Tue Mar 02, 2010 6:47 pm
by 9232061
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 5557 times
Many thanks, Doug

Re: AxisValuesFormat has no effect

Posted: Wed Mar 03, 2010 4:01 pm
by yeray
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;

Re: AxisValuesFormat has no effect

Posted: Wed Mar 03, 2010 7:17 pm
by 9232061
That solved it Yeray, once again thank-you!