Page 1 of 1
An axis glitch ....
Posted: Fri Aug 13, 2010 6:33 am
by 8751509
Greetings,
I have a tricky one ... my Right Axis (Which is axis.left and axes.left.otherside = true)
- axisGoodBehaviour.png (5.25 KiB) Viewed 8049 times
All working as expected ..
However when I add a custom axis to the right ... it does not adjust to allow room for the scale values. (see below)
- axisBad.png (12.27 KiB) Viewed 8046 times
I have set the axis to automatic
Code: Select all
StockChart.Axes.Left.Automatic = true;
StockChart.Axes.Bottom.Automatic = true;
But no luck there ... is there a property I am not setting that will enable the chart to adjust accordingly?
Re: An axis glitch ....
Posted: Fri Aug 13, 2010 4:03 pm
by yeray
Hi Phil,
The chart doesn't adjust the margins automatically for the Custom axes. So you have to do it manually:
Code: Select all
StockChart.Panel.MarginRight = 10;
Re: An axis glitch ....
Posted: Mon Aug 16, 2010 12:37 am
by 8751509
Thanks Yeray,
Ok I understand .. is there a way to determine how many pixels the Custom axis' label text is ..
For example if the Axis lable is "5,000,000,000" .. can I determine how many pixels this takes up so I can adjust the axis manually ...
Cheers Phil.
Re: An axis glitch ....
Posted: Mon Aug 16, 2010 9:11 am
by yeray
Hi Phil,
Yes, you could call the following once the chart has been drawn (so you may also need to call tChart1.Draw()):
Code: Select all
tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
tChart1.Panel.MarginRight = tChart1.Axes.Left.MaxLabelsWidth() + tChart1.Axes.Left.Ticks.Length;
Re: An axis glitch ....
Posted: Thu Nov 04, 2010 1:33 am
by 8751509
Hi Yeray,
I tried the supplied code ... but it doesn't seem to be working predictably.
Code: Select all
private void StockChart_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
StockChart.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
StockChart.Panel.MarginRight = StockChart.Axes.Left.MaxLabelsWidth() +StockChart.Axes.Left.Ticks.Length;
Debug.Print("MarginRight: " + StockChart.Panel.MarginRight.ToString());
}
My full code is somethign like this
Code: Select all
StockChart.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
double maxMargin = StockChart.Axes.Left.MaxLabelsWidth() + StockChart.Axes.Left.Ticks.Length;
foreach (Axis axis in StockChart.Axes.Custom)
{
double tmp = axis.MaxLabelsWidth() + axis.Ticks.Length;
if (maxMargin < tmp)
{
maxMargin = tmp;
}
}
StockChart.Panel.MarginRight = maxMargin;
But it still overestimates the Label size and not by any constant value that I could adjust the Margin value by .. i.e. 50%
When I first open my chart the axis labels render like so
- flakey1.png (3.65 KiB) Viewed 7978 times
When I add a custom axis with much larger labels the spacing doesnt change.(but by luck happens to fit)
- flakey2.png (5.66 KiB) Viewed 7975 times
When I change to another instrument that has larger labels I again have quite a gap
- flakey3.png (4.1 KiB) Viewed 7977 times
Does it matter that my 'Right Axis' is actually the 'Left Axis' with the 'otherside' property set to true?
I'm guessing the main problem I am having is that it is calculating a far bigger label size than is actually being drawn.
And I am assuming that I need to do this routine for EVERY vertical axis and Custom axis.
Re: An axis glitch ....
Posted: Thu Nov 04, 2010 11:29 am
by narcis
Hi Phil,
What about doing something like in the example below?
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
tChart1.Legend.Visible = false;
tChart1.Aspect.View3D = false;
tChart1.Series.Add(new Steema.TeeChart.Styles.Line()).FillSampleValues(100);
tChart1.Series.Add(new Steema.TeeChart.Styles.Line());
Random y = new Random();
for (int i = 0; i < 100; i++)
{
tChart1[1].Add(y.Next());
}
tChart1.Axes.Left.OtherSide = true;
tChart1.Axes.Left.EndPosition = 50;
Steema.TeeChart.Axis axis1 = new Steema.TeeChart.Axis(false, true, tChart1.Chart);
tChart1.Axes.Custom.Add(axis1);
axis1.StartPosition = 50;
tChart1[1].CustomVertAxis = axis1;
CalcMargins();
}
private void CalcMargins()
{
tChart1.Draw();
double maxWidth = 0;
for (int i = 0; i < tChart1.Axes.Count; i++)
{
Steema.TeeChart.Axis a = tChart1.Axes[i];
if (!a.Horizontal)
{
double tmp = tChart1.Graphics3D.TextWidth(a.Labels.Font, a.Maximum.ToString());
maxWidth = Math.Max(maxWidth, tmp);
}
}
tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
tChart1.Panel.MarginRight = maxWidth;
}
Hope this helps!
Re: An axis glitch ....
Posted: Fri Nov 05, 2010 1:14 am
by 8751509
no that did the same thing ... but I might have an idea why with the last bit of code ...
double tmp = StockChart.Graphics3D.TextWidth(a.Labels.Font, a.Maximum.ToString());
Should be bullet proof if I understand it correctly.
What I suspect here is that a.Maximum can happily be a value such as 15.348578857994885959
even though it would only be displayed to 2 or 3 decimal points (i.e. 15.34 ) ... so its calculating on a string that is much much larger than the visible display value.
I'll keep playing with it .. see if I'm right ... I'll try truncating the Maximum value to a form that reflects what is being displayed.
Would axis.MaxLabelsWidth() have the same issue .. does it use StockChart.Graphics3D.TextWidth() behind the scenes ...
Re: An axis glitch ....
Posted: Fri Nov 05, 2010 9:56 am
by narcis
Hi Phil,
Yes, exactly, internally MaxLabelsWidth() uses TextWidth. Having that in mind you can modify CalcMargins to convert axis maximum to a string with the same format as axis labels and then calculate its width, for example:
Code: Select all
private void CalcMargins()
{
tChart1.Draw();
double maxWidth = 0;
for (int i = 0; i < tChart1.Axes.Count; i++)
{
Steema.TeeChart.Axis a = tChart1.Axes[i];
if (!a.Horizontal)
{
string maxLabel = String.Format("{0:" + a.Labels.ValueFormat + "}", a.Maximum.ToString());
double tmpWidth = tChart1.Graphics3D.TextWidth(a.Labels.Font, maxLabel);
maxWidth = Math.Max(maxWidth, tmpWidth);
}
}
tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
tChart1.Panel.MarginRight = maxWidth;
}
Hope this helps!
Re: An axis glitch ....
Posted: Tue Nov 09, 2010 5:32 am
by 8751509
closer still but not quite ...
Its getting the text formatting information and the maximum values .. but the maximum values still have decimal points in them and so even with the formatting are still beign calculated slightly larger than what is being displayed ...
Is there a way to grab the largest Label on an axis and in most cases I mean the top label on an axis ...
i.e. an axis runs from 5 - 12000 ... the max value may well be 12000.12345 ... but the label is 'nice' number of 12000 .. on which I'd like to base the scaling.
My custom axis are all set to AUTO the string mask is #,##0.### .. so the max value will get decimal places as well.
Re: An axis glitch ....
Posted: Tue Nov 09, 2010 10:03 am
by narcis
Hi Phil,
The only option I can think of is using GetAxisLabel or GetNextAxisLabel events as in the example below.
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
tChart1.Legend.Visible = false;
tChart1.Aspect.View3D = false;
tChart1.Series.Add(new Steema.TeeChart.Styles.Line()).FillSampleValues(100);
tChart1.Series.Add(new Steema.TeeChart.Styles.Line());
Random y = new Random();
for (int i = 0; i < 100; i++)
{
tChart1[1].Add(y.Next());
}
tChart1.Axes.Left.OtherSide = true;
tChart1.Axes.Left.EndPosition = 50;
tChart1.Axes.Left.Labels.ValueFormat = "#,##0.###";
Steema.TeeChart.Axis axis1 = new Steema.TeeChart.Axis(false, true, tChart1.Chart);
tChart1.Axes.Custom.Add(axis1);
axis1.StartPosition = 50;
axis1.Labels.ValueFormat = "#,##0.###";
tChart1[1].CustomVertAxis = axis1;
tChart1.GetAxisLabel += new Steema.TeeChart.GetAxisLabelEventHandler(tChart1_GetAxisLabel);
CalcMargins();
}
double maxLength = 0;
void tChart1_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
{
Steema.TeeChart.Axis a = (Steema.TeeChart.Axis)sender;
if (!a.Horizontal)
{
double tmpWidth = tChart1.Graphics3D.TextWidth(a.Labels.Font, e.LabelText);
maxLength = Math.Max(maxLength, tmpWidth);
}
}
private void CalcMargins()
{
tChart1.Draw();
//double maxWidth = 0;
//for (int i = 0; i < tChart1.Axes.Count; i++)
//{
// Steema.TeeChart.Axis a = tChart1.Axes[i];
// if (!a.Horizontal)
// {
// string maxLabel = String.Format("{0:" + a.Labels.ValueFormat + "}", a.Maximum.ToString());
// double tmpWidth = tChart1.Graphics3D.TextWidth(a.Labels.Font, maxLabel);
// maxWidth = Math.Max(maxWidth, tmpWidth);
// }
//}
tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
tChart1.Panel.MarginRight = maxLength;// maxWidth;
}
Re: An axis glitch ....
Posted: Wed Nov 10, 2010 5:08 am
by 8751509
Tnx Narcis,
I ended up going back to the previous version ... but by being a little more aggressive about setting the ValueFormat string instead of leaving the custom axis as auto its working fairly well now ...
thanks for the support.