Page 1 of 1

Formatting Numeric Axis Labels

Posted: Mon Feb 20, 2006 1:36 pm
by 9638326
Hi there,

Is there any way to show values on ticks in a chart in scientific format? I need this option for both axis but could not figure it out using the options given. Would be great if one could make this depending on the value as well, e.g. for values larger than xxx.

Console.Write("{0:E}", 62000); => 6.200000E+004
but for axis labels ,)

Thanks,
Regards,
Robert

Posted: Mon Feb 20, 2006 2:31 pm
by narcis
Hi Robert,

Yes, there's an example of that at All Features\Welcome !\Axes\Labels\Exponent superscript in TeeChart's features demo. You'll find that demo at TeeChart's program group.

Posted: Mon Feb 20, 2006 3:07 pm
by 9638326
Oops thank you! I didnt catch up this one :oops:
Workin now, thanks again:)
Robert

Posted: Mon Feb 20, 2006 4:16 pm
by 9638326
Hi again,

here is another one! How to fix scientific view to E+3 for ALL labels even those who would normally get an E+2 etc e.g.
1000 => 1x10^3
100 => 0.1x10^3 and not 1x10^2 ?

Thanks again,
Robert

Posted: Wed Feb 22, 2006 10:44 am
by narcis
Hi Robert,

This is not supported by .NET's Framework as you can see [url=ms-help://MS.VSCC.2003/MS.MSDNQTR.2006JAN.1033/cpref/html/frlrfsystemdoubleclasstostringtopic3.htm]here[/url]. However, you can achieve that manually parsing labels text using the GetAxisLabel method and some code like this:

Code: Select all

		private void Form1_Load(object sender, System.EventArgs e)
		{
			for (int i=0;i<=10000;i=i+10) line1.Add(i);

			tChart1.Axes.Left.Labels.Exponent = true;
			tChart1.Axes.Left.Labels.ValueFormat = "#.0 x10 E+0";
		}

		private int exponent=3;

		private void tChart1_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
		{
			if (sender==tChart1.Axes.Left)
			{
				if (!(e.LabelText.EndsWith("E+"+exponent.ToString())))
				{
					//Parsing the exponent
					int ExpIndex=e.LabelText.IndexOf("E");
					string CurrExpStr=e.LabelText.Substring(ExpIndex+2);
					
					e.LabelText=e.LabelText.Replace("E+"+CurrExpStr,"E+"+exponent.ToString());

					//Parsing the value
					int ExpDiff=exponent-Convert.ToInt16(CurrExpStr);					
					int ValIndex=e.LabelText.IndexOf(" x");
					string ValStr=e.LabelText.Remove(ValIndex,e.LabelText.Length-ValIndex);
					double Val=Convert.ToDouble(ValStr);

					Val = ExpDiff>0 ? Val/(10*ExpDiff) : Val*(10*Math.Abs(ExpDiff));
					e.LabelText=e.LabelText.Replace(ValStr,Val.ToString());		
				}
			}
		}