How to display red numbers on the X-axis

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Newbie
Newbie
Posts: 27
Joined: Wed Nov 09, 2022 12:00 am

How to display red numbers on the X-axis

Post by » Tue Jun 27, 2023 9:14 am

[img]C://Users//lyl//Desktop//222.png[/img]

How to display red numbers on the X-axis???
Attachments
222.png
222.png (136.64 KiB) Viewed 24372 times

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

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

Post by Yeray » Tue Jun 27, 2023 11:44 am

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 24368 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 24368 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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Newbie
Newbie
Posts: 27
Joined: Wed Nov 09, 2022 12:00 am

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

Post by » Wed Jun 28, 2023 1:42 am

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

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

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

Post by Yeray » Wed Jun 28, 2023 5:55 am

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Newbie
Newbie
Posts: 27
Joined: Wed Nov 09, 2022 12:00 am

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

Post by » Thu Jun 29, 2023 2:17 am

[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;

Newbie
Newbie
Posts: 27
Joined: Wed Nov 09, 2022 12:00 am

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

Post by » Thu Jun 29, 2023 2:20 am

C://Users//lyl//Desktop//333.png

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

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

Post by Yeray » Thu Jun 29, 2023 6:50 am

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Newbie
Newbie
Posts: 27
Joined: Wed Nov 09, 2022 12:00 am

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

Post by » Fri Jun 30, 2023 3:21 am

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.
Attachments
333.png
333.png (16.85 KiB) Viewed 24260 times

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

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

Post by Yeray » Fri Jun 30, 2023 6:24 am

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Newbie
Newbie
Posts: 27
Joined: Wed Nov 09, 2022 12:00 am

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

Post by » Mon Jul 03, 2023 1:36 am

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?

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

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

Post by Yeray » Mon Jul 03, 2023 5:59 am

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply