Incorrect left axis position when changing labels text with GetAxisDrawLabel event

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
bairog
Advanced
Posts: 128
Joined: Fri Dec 07, 2018 12:00 am

Incorrect left axis position when changing labels text with GetAxisDrawLabel event

Post by bairog » Wed Sep 20, 2023 5:54 am

Hello.
I use latest Steema.TeeChart.NET 4.2023.8.31 in my WinForms App targeting .NET Framework 4.8 (I use latest VS Enterprise 2022 17.7.4).
I have two charts on my form: on charts I display same set of hours (0 .. 9) as bars, but on 2nd chart I convert hours to seconds (*3600).
Because on 2nd chart Y values ​​are bigger, the Y axis is moved to the right (to make labels fit) - that's expected behaviour.
Image
If I use GetAxisDrawLabel event to format label text back to hours Y axis still at the same position despite of labels become much smaller:
Image
  1. How to move the Y axis further to the left (so that there is space needed only to draw the labels)? Do I need to call some extra function to make chart to recalculate Y axis position?
  2. Is it possible to move the Y axis further to the left (even on 1st chart)? I think chart reserves more space than needed to draw labels.

Code: Select all

public Form1()
{
    InitializeComponent();
    
    tChart2.Axes.Left.GetAxisDrawLabel += Left_GetAxisDrawLabel;

    Random rnd = new Random();
    for (int x = 0; x < 10; x++)
    {
        var y = rnd.Next(10);

        bar1.Add(x, y);
        bar2.Add(x, y * 3600);                
    }
}

private void Left_GetAxisDrawLabel(object sender, Steema.TeeChart.GetAxisDrawLabelEventArgs e)
{
    e.Text = (e.LabelValue / 3600).ToString("0");
}

bairog
Advanced
Posts: 128
Joined: Fri Dec 07, 2018 12:00 am

Re: Incorrect left axis position when changing labels text with GetAxisDrawLabel event

Post by bairog » Mon Sep 25, 2023 5:18 am

Hmm, 5 days have passed (a full 3 business days) - still no reaction. Very disappointing..

Marc
Site Admin
Site Admin
Posts: 1265
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Incorrect left axis position when changing labels text with GetAxisDrawLabel event

Post by Marc » Mon Sep 25, 2023 1:35 pm

Hello,

Sorry for the delay with the reply.

We recommend to use the Axis Labels CustomSize property:

Code: Select all

 tChart1.Axes.Left.FixedLabelSize = false;
 tChart1.Axes.Left.Labels.CustomSize = 80;
Regards,
Marc Meumann
Steema Support

bairog
Advanced
Posts: 128
Joined: Fri Dec 07, 2018 12:00 am

Re: Incorrect left axis position when changing labels text with GetAxisDrawLabel event

Post by bairog » Tue Sep 26, 2023 4:59 am

Marc wrote:
Mon Sep 25, 2023 1:35 pm
We recommend to use the Axis Labels CustomSize property:

Code: Select all

 tChart1.Axes.Left.FixedLabelSize = false;
 tChart1.Axes.Left.Labels.CustomSize = 80;
To determine Axes.Left.Labels.CustomSize value that I need I am to measure axis label size in pixels somehow (that value is in pixels, right?). Respecting axis labels font settings of course. How can I do that?

Marc
Site Admin
Site Admin
Posts: 1265
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Incorrect left axis position when changing labels text with GetAxisDrawLabel event

Post by Marc » Tue Sep 26, 2023 7:21 am

Hello,

Something like this would do it:

Code: Select all

  tChart1.Axes.Left.FixedLabelSize = false;
  tChart2.Axes.Left.FixedLabelSize = false;

  if (tChart1.Axes.Left.MaxLabelsWidth() > tChart2.Axes.Left.MaxLabelsWidth())
  {
    tChart1.Axes.Left.Labels.CustomSize = tChart1.Axes.Left.MaxLabelsWidth();
    tChart2.Axes.Left.Labels.CustomSize = tChart1.Axes.Left.MaxLabelsWidth();
  }
  else
  {
    tChart1.Axes.Left.Labels.CustomSize = tChart2.Axes.Left.MaxLabelsWidth();
    tChart2.Axes.Left.Labels.CustomSize = tChart2.Axes.Left.MaxLabelsWidth();
  }
Regards,
Marc
Steema Support

Post Reply