Page 1 of 1
Margin with custom axis
Posted: Tue Jan 21, 2014 10:22 am
by 15654539
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,
Re: Margin with custom axis
Posted: Tue Jan 21, 2014 5:15 pm
by Christopher
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?
Re: Margin with custom axis
Posted: Wed Jan 22, 2014 9:51 am
by 15654539
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.
Re: Margin with custom axis
Posted: Wed Jan 22, 2014 10:21 am
by Christopher
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 (24.62 KiB) Viewed 17773 times
- labels2.png (22.67 KiB) Viewed 17776 times
- labels3.png (23.9 KiB) Viewed 17773 times
I'm not sure what the problem is with any of these images - could you please explain it to me?
Re: Margin with custom axis
Posted: Wed Jan 22, 2014 10:38 am
by 15654539
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?
Re: Margin with custom axis
Posted: Wed Jan 22, 2014 11:01 am
by Christopher
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.
Re: Margin with custom axis
Posted: Wed Jan 22, 2014 11:34 am
by 15654539
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
Re: Margin with custom axis
Posted: Wed Jan 22, 2014 11:54 am
by Christopher
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);
}
Re: Margin with custom axis
Posted: Thu Jan 23, 2014 11:01 am
by 15654539
It doesn't run very well, is it possible to resize manually of the chart rectangle to get the same effect than automatically
Re: Margin with custom axis
Posted: Thu Jan 23, 2014 11:16 am
by Christopher
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);
}