Margin with custom axis

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Margin with custom axis

Post by acastro » Tue Jan 21, 2014 10:22 am

Hello,
Please find attached an example to understand my question
http://193.145.251.126/pnp/files/yxAwTREaT/labels.ten

If you open the chart editor and switch in the first serie the left axis of the serie between "Left" and "Custom 0" you can see with the left margin changes, and sometimes with "Custom 0" you cannot see the whole labels in the left axis. I have find the difference between left and custom 0 axis regarding to this margin but I didn't find it, how can I configurate my custom axis to have the same margin as "Left" axis?

Thanks in advance,

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Margin with custom axis

Post by Christopher » Tue Jan 21, 2014 5:15 pm

wakeup wrote:I have find the difference between left and custom 0 axis regarding to this margin but I didn't find it, how can I configurate my custom axis to have the same margin as "Left" axis?
This seems to work okay at runtime, e.g.

Code: Select all

    private void InitializeChart()
    {
      tChart1.Import.Template.Load(@"C:\tmp\labels.ten");
      tChart1[1].CustomVertAxis = null;
    }
Can you please confirm if this code reliably renders the axes correctly?
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Margin with custom axis

Post by acastro » Wed Jan 22, 2014 9:51 am

Yes but you are disabling the custom axis, I want to have the custom axis but having the same behaviour in the margin as the "Lef" axis.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Margin with custom axis

Post by Christopher » Wed Jan 22, 2014 10:21 am

wakeup wrote:Yes but you are disabling the custom axis, I want to have the custom axis but having the same behaviour in the margin as the "Lef" axis.
here is the code I'm using:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Import.Template.Load(@"C:\tmp\labels.ten");  //labels1.png

      //tChart1.Panel.MarginLeft = 10; //uncomment for labels2.png
      //tChart1[1].CustomVertAxis = null; //uncomment for labels3.png
    }
and here are the three resulting images:
labels1.png
labels1.png (24.62 KiB) Viewed 18027 times
labels2.png
labels2.png (22.67 KiB) Viewed 18030 times
labels3.png
labels3.png (23.9 KiB) Viewed 18027 times
I'm not sure what the problem is with any of these images - could you please explain it to me?
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Margin with custom axis

Post by acastro » Wed Jan 22, 2014 10:38 am

I want to have the Label2.png result, but without changing the MarginLeft to 10. I mean, If I put the axis "Left" it is shown correctly with MarginLeft =3. Why with axis "Custom 0" it now shown in the same way with MarginLeft = 3?

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Margin with custom axis

Post by Christopher » Wed Jan 22, 2014 11:01 am

wakeup wrote:I want to have the Label2.png result, but without changing the MarginLeft to 10. I mean, If I put the axis "Left" it is shown correctly with MarginLeft =3. Why with axis "Custom 0" it now shown in the same way with MarginLeft = 3?
This is because custom axes are behave differently to the default axes, and this difference is by design. Custom axes do not automatically resize the Chart rectangle, as default axes do, which means the margins have to be set manually.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Margin with custom axis

Post by acastro » Wed Jan 22, 2014 11:34 am

Christopher wrote:Custom axes do not automatically resize the Chart rectangle, as default axes do, which means the margins have to be set manually.
Why not? I think it would be logical to have the same behaviour...

Do you have any code to set this margins automatically? I mean depending on the size of the chart and the lenght of the labels in the axis...

Thanks

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Margin with custom axis

Post by Christopher » Wed Jan 22, 2014 11:54 am

wakeup wrote: Why not? I think it would be logical to have the same behaviour...
Default axes position are known by the TeeChart code, that is why they are default. Knowing the position means that some calculations can be done to resize the chart rectangle. Custom axes positions are not known by the TeeChart code, they are set by the user. This means that calculations involving the resizing of the chart rectangle cannot be done automatically.
wakeup wrote: Do you have any code to set this margins automatically? I mean depending on the size of the chart and the lenght of the labels in the axis...
You could try something similar to this:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Import.Template.Load(@"C:\tmp\labels.ten");  //labels1.png
      tChart1.Draw();

      double maxVal = tChart1[1].YValues.Maximum;

      float width = tChart1.Graphics3D.TextWidth(maxVal.ToString(tChart1.Axes.Custom[0].Labels.ValueFormat));

      tChart1.Panel.MarginUnits = PanelMarginUnits.Pixels;
      tChart1.Panel.MarginLeft = Utils.Round(width * 1.1);
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Margin with custom axis

Post by acastro » Thu Jan 23, 2014 11:01 am

It doesn't run very well, is it possible to resize manually of the chart rectangle to get the same effect than automatically

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Margin with custom axis

Post by Christopher » Thu Jan 23, 2014 11:16 am

wakeup wrote:It doesn't run very well, is it possible to resize manually of the chart rectangle to get the same effect than automatically
In what sense does it not run very well? The code snippet runs as expected here.

And yes, you can manually resize the ChartRect with the following code:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Series.Add(typeof(Line)).FillSampleValues();
      tChart1.Chart.CustomChartRect = true;
      tChart1.Chart.ChartRect = Utils.FromLTRB(100, 100, 300, 300); 
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply