Hi,
I am drawing multiple axes on one chart. They are organised horizontally, and the spacing between them I set according to MaxLabelsWidth so I can get the best possible fit.
The problem is It randomly gives me an exception. The exception occurs in System.Drawing.Graphics.MeasureString(...)
Having googled this, it seems to be a common problem and indicates a bug in MeasureString(). Do you have any suggestions to find the width I need for an axis?
The axes are using AutoMatic mode for some and preset for others.
thanks,
System.ArgumentException occurred
Message="Parameter is not valid."
Source="System.Drawing"
StackTrace:
at System.Drawing.Graphics.MeasureString(String text, Font font, SizeF layoutArea, StringFormat stringFormat)
at System.Drawing.Graphics.MeasureString(String text, Font font, SizeF layoutArea)
at System.Drawing.Graphics.MeasureString(String text, Font font)
at Steema.TeeChart.Drawing.Graphics3DGdiPlus.MeasureString(ChartFont f, String text)
at Steema.TeeChart.Drawing.Graphics3D.TextWidth(String text)
at Steema.TeeChart.Chart.MultiLineTextWidth(String s, Int32& numLines)
at Steema.TeeChart.AxisLabels.InternalLabelSize(Double value, Boolean isWidth)
at Steema.TeeChart.AxisLabels.LabelHeight(Double value)
at Steema.TeeChart.Axis.get_CalcIncrement()
at Steema.TeeChart.Axis.MaxLabelsValueWidth()
at Steema.TeeChart.Axis.MaxLabelsWidth()
at TE.TI.Trend.UI.TrendControl.SetAxisPlacement(Boolean fUseGraphics) in E:\workspaces\trend\tipsinfoviewer\src\TE.TI.Trend.UI\TrendControl.cs:line 1048
Exception in axis.MaxLabelsWidth()
-
- Site Admin
- Posts: 1349
- Joined: Thu Jan 01, 1970 12:00 am
- Location: Riudellots de la Selva, Catalonia
- Contact:
Hello,
Well, googling also led me to a number of alternatives to MeasureString which you could probably implement in the GetAxisLabels event to calculate the MaxLabelsWidth manually.
Well, googling also led me to a number of alternatives to MeasureString which you could probably implement in the GetAxisLabels event to calculate the MaxLabelsWidth manually.
Thank you!
Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/
Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/
-
- Site Admin
- Posts: 1349
- Joined: Thu Jan 01, 1970 12:00 am
- Location: Riudellots de la Selva, Catalonia
- Contact:
Hello,
More on this. Just wanted to thank you for pointing this one out to me as removing the depency on Graphics.MeasureString from the TeeChart method Graphics3DGdiPlus.MeasureString has resolved a couple of long standing issue's I've had.
Our code for MeasureString (available in the next maintenance release) now looks like this:
More on this. Just wanted to thank you for pointing this one out to me as removing the depency on Graphics.MeasureString from the TeeChart method Graphics3DGdiPlus.MeasureString has resolved a couple of long standing issue's I've had.
Our code for MeasureString (available in the next maintenance release) now looks like this:
Code: Select all
public override SizeF MeasureString(ChartFont f,string text)
{
if (g==null)
{
//MM Alternative approach required for Win98
Bitmap b=new Bitmap(1,1);
g=Graphics.FromImage(b);
}
return MeasureDisplayStringWidth(text, f.DrawingFont);
}
public SizeF MeasureDisplayStringWidth(string text, Font font)
{
System.Drawing.StringFormat format = new System.Drawing.StringFormat();
System.Drawing.RectangleF rect = new System.Drawing.RectangleF(0, 0,
1000, 1000);
System.Drawing.CharacterRange[] ranges =
{ new System.Drawing.CharacterRange(0,
text.Length) };
System.Drawing.Region[] regions = new System.Drawing.Region[1];
format.SetMeasurableCharacterRanges(ranges);
regions = g.MeasureCharacterRanges(text, font, rect, format);
rect = regions[0].GetBounds(g);
rect.Inflate(1, 1);
return rect.Size;
}
Thank you!
Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/
Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/
-
- Site Admin
- Posts: 1349
- Joined: Thu Jan 01, 1970 12:00 am
- Location: Riudellots de la Selva, Catalonia
- Contact:
Hello,
You don't have to wait until then if you don't want to. You can override the Graphics3DGdiPlus class and override the MeasureString method using the code I mentioned below. Then all you have to do is to set an instance of this new class to tChart.Graphics3D and do a tChart.Invalidate.
You don't have to wait until then if you don't want to. You can override the Graphics3DGdiPlus class and override the MeasureString method using the code I mentioned below. Then all you have to do is to set an instance of this new class to tChart.Graphics3D and do a tChart.Invalidate.
Thank you!
Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/
Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/