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.
Many thanks, Doug
AxisValuesFormat has no effect
Re: AxisValuesFormat has no effect
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:
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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: AxisValuesFormat has no effect
That solved it Yeray, once again thank-you!