Page 1 of 1

How to display red numbers on the X-axis

Posted: Tue Jun 27, 2023 9:14 am
by 16494694
[img]C://Users//lyl//Desktop//222.png[/img]

How to display red numbers on the X-axis???

Re: How to display red numbers on the X-axis

Posted: Tue Jun 27, 2023 11:44 am
by yeray
Hello,

If you want all the labels in the bottom axis to be red you can just set the Bottom axis LabelsFont.Color:
Project1_2023-06-27_12-20-30.png
Project1_2023-06-27_12-20-30.png (20.24 KiB) Viewed 24836 times

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Align:=alClient;
  Chart1.Color:=clWhite;
  Chart1.Gradient.Visible:=False;
  Chart1.Walls.Back.Color:=clWhite;
  Chart1.Walls.Back.Gradient.Visible:=False;

  Chart1.View3D:=False;
  Chart1.Legend.Hide;

  Chart1.AddSeries(TFastLineSeries).FillSampleValues(10);

  Chart1.Axes.Bottom.Title.Text:='Time (sec)';
  Chart1.Axes.Bottom.LabelsFont.Color:=clRed;
end;
If you want only some labels in the bottom axis to be red, you have two options:

You can use the OnDrawLabel event to change the Bottom axis LabelsFont.Color accordingly:
Project1_2023-06-27_12-39-43.png
Project1_2023-06-27_12-39-43.png (18.09 KiB) Viewed 24836 times

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Align:=alClient;
  Chart1.Color:=clWhite;
  Chart1.Gradient.Visible:=False;
  Chart1.Walls.Back.Color:=clWhite;
  Chart1.Walls.Back.Gradient.Visible:=False;

  Chart1.View3D:=False;
  Chart1.Legend.Hide;

  Chart1.AddSeries(TFastLineSeries).FillSampleValues(11);

  Chart1.Axes.Bottom.Title.Text:='Time (sec)';

  Chart1.Axes.Bottom.OnDrawLabel:=BottomAxisDrawLabel
end;

procedure TForm1.BottomAxisDrawLabel(Sender:TChartAxis; var X,Y,Z:Integer; var Text:String; var DrawLabel:Boolean);
begin
  if (Text<>'0') and (Text<>'10') then
     Sender.LabelsFont.Color:=clRed
  else
     Sender.LabelsFont.Color:=clBlack;
end;
Or you can use custom labels to achieve the same fine control and the same result. Ie:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1.Align:=alClient;
  Chart1.Color:=clWhite;
  Chart1.Gradient.Visible:=False;
  Chart1.Walls.Back.Color:=clWhite;
  Chart1.Walls.Back.Gradient.Visible:=False;

  Chart1.View3D:=False;
  Chart1.Legend.Hide;

  Chart1.AddSeries(TFastLineSeries).FillSampleValues(11);

  Chart1.Axes.Bottom.Title.Text:='Time (sec)';

  Chart1.Draw;

  with Chart1.Axes.Bottom do
  begin
    Items.Automatic:=False;
    for i:=0 to Items.Count-1 do
      if (Items[i].Text<>'0') and (Items[i].Text<>'10') then
         Items[i].Format.Font.Color:=clRed;
  end;
end;

Re: How to display red numbers on the X-axis

Posted: Wed Jun 28, 2023 1:42 am
by 16494694
You misunderstood!!!

What I mean is that the X-axis now only displays 1, 5, and 10. How to make the X-axis display 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

That is to say, how to make the X-axis display more value text

Re: How to display red numbers on the X-axis

Posted: Wed Jun 28, 2023 5:55 am
by yeray
Hello,

By default, the Axis Increment is set to 0 which automatically tries to fit as many labels as possible.
Did you change this setting?
You can change it again:

Code: Select all

Chart1.Axes.Bottom.Increment:=0;
Or, if you want to force those labels, you can set it to 1:

Code: Select all

Chart1.Axes.Bottom.Increment:=1;

Re: How to display red numbers on the X-axis

Posted: Thu Jun 29, 2023 2:17 am
by 16494694
[img]C://Users//ly//Desktop//333.png[/img]

This effect is not very good, it should be more. Can you modify your implementation process???
Chart1.Axes.Bottom.Increment:=0;

Re: How to display red numbers on the X-axis

Posted: Thu Jun 29, 2023 2:20 am
by 16494694
C://Users//lyl//Desktop//333.png

Re: How to display red numbers on the X-axis

Posted: Thu Jun 29, 2023 6:50 am
by yeray
Hello,

I see you still have troubles trying to attach your images.
I've improved my reply here about how to insert images to this forums.

Re: How to display red numbers on the X-axis

Posted: Fri Jun 30, 2023 3:21 am
by 16494694
I have added the image to the attachment!

I suggest that you modify the insert image function to pop up a dialog box for users to select an image. This is a formal practice for many software applications.

Re: How to display red numbers on the X-axis

Posted: Fri Jun 30, 2023 6:24 am
by yeray
Hello,
wrote:
Fri Jun 30, 2023 3:21 am
I have added the image to the attachment!
If you want labels at 0, 1, 2,..., and you want to force it so labels 0.5, 1, 1.5,... don't appear when zooming, you can set Increment:=1.
wrote:
Fri Jun 30, 2023 3:21 am
I suggest that you modify the insert image function to pop up a dialog box for users to select an image. This is a formal practice for many software applications.
You can press the "Add files" button in the "Attachments" tab to open the file explorer. I've edited the explanation here to mention it.

Re: How to display red numbers on the X-axis

Posted: Mon Jul 03, 2023 1:36 am
by 16494694
It's not necessary to have an interval of 1. What I mean is whether it's possible to display as many numbers as possible during adaptation?

Re: How to display red numbers on the X-axis

Posted: Mon Jul 03, 2023 5:59 am
by yeray
Hello,

Try setting an Increment of 0.5, or to the minimum increment you want to support in your app.

If you still find problems with it, please arrange a simple example project we can run as-is to reproduce the problem here.
Thanks in advance.