Page 1 of 1

Incorrect left axis position when changing labels text with GetAxisDrawLabel event

Posted: Wed Sep 20, 2023 5:54 am
by 15685014
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");
}

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

Posted: Mon Sep 25, 2023 5:18 am
by 15685014
Hmm, 5 days have passed (a full 3 business days) - still no reaction. Very disappointing..

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

Posted: Mon Sep 25, 2023 1:35 pm
by Marc
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

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

Posted: Tue Sep 26, 2023 4:59 am
by 15685014
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?

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

Posted: Tue Sep 26, 2023 7:21 am
by Marc
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