Page 1 of 1

How to get "rounded" Axis Labels?

Posted: Wed Sep 09, 2020 12:16 pm
by 16586272
Although the following codes are used, Axis Labels of Increment, Minimum and Maximum values does not show a "rounded" value. What's the story?

Code: Select all

      for i := 0 to aChart.Axes.Count - 1 do
        begin
          with Axes[i] do
            begin
              ……
              Automatic := true;
              RoundFirstLabel := true;
              MinimumRound := true;
              MaximumRound := true;
              ……
            end;
        end;

Re: How to get "rounded" Axis Labels?

Posted: Thu Sep 10, 2020 2:03 pm
by yeray
Hello,

I'm trying to reproduce the problem without success.
Could you please arrange a simple example project we can run as-is to reproduce the problem here?
Thanks in advance.

Re: How to get "rounded" Axis Labels?

Posted: Fri Sep 11, 2020 1:12 am
by 16586272
Got the problem. The reason is that the following code is used for TChart.Axes.
LabelsSeparation := 0;
So, TChartAxis skip calculating overlapping labels.

By default, Axis Labels are often too sparse. Is there a better way to mark Axis Labels as closely as possible? Except, LabelsSeparation := 1.

Re: How to get "rounded" Axis Labels?

Posted: Tue Sep 15, 2020 6:58 am
by yeray
Hello,
xsLiu wrote:
Fri Sep 11, 2020 1:12 am
Is there a better way to mark Axis Labels as closely as possible? Except, LabelsSeparation := 1.
I'm afraid the only alternative would be to manually populate the labels yourself. Ie:

Code: Select all

var lHeight: Integer;
    curVal: Double;
    dif: Double;
begin
  Chart1.AddSeries(TPointSeries).FillSampleValues(10);
  lHeight:=Chart1.Axes.Left.LabelHeight(Chart1[0].YValues.MaxValue);

  Chart1.Draw;
  dif:=Chart1.Axes.Left.CalcPosPoint(Chart1.Axes.Left.CalcPosValue(Chart1[0].YValues.MaxValue)+lHeight)-Chart1[0].YValues.MaxValue;
  curVal:=Chart1[0].YValues.MaxValue;
  Chart1.Axes.Left.Items.Clear;
  while curVal>=Chart1[0].YValues.MinValue do
  begin
    Chart1.Axes.Left.Items.Add(curVal, FormatFloat('#.##0,##', curVal));
    curVal:=curVal+dif;
  end;
  Chart1.Axes.Left.Items.Add(curVal, FormatFloat('#.##0,##', curVal));
end;