Formatting Numeric Axis Labels

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Torte
Newbie
Newbie
Posts: 19
Joined: Fri Sep 16, 2005 4:00 am

Formatting Numeric Axis Labels

Post by Torte » Mon Feb 20, 2006 1:36 pm

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Feb 20, 2006 2:31 pm

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Torte
Newbie
Newbie
Posts: 19
Joined: Fri Sep 16, 2005 4:00 am

Post by Torte » Mon Feb 20, 2006 3:07 pm

Oops thank you! I didnt catch up this one :oops:
Workin now, thanks again:)
Robert

Torte
Newbie
Newbie
Posts: 19
Joined: Fri Sep 16, 2005 4:00 am

Post by Torte » Mon Feb 20, 2006 4:16 pm

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Feb 22, 2006 10:44 am

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());		
				}
			}
		}
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply