X,Y,Z from Axis Labels

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
JayG
Newbie
Newbie
Posts: 71
Joined: Mon Sep 04, 2006 12:00 am

X,Y,Z from Axis Labels

Post by JayG » Tue Dec 11, 2007 10:59 pm

I'm using TeeChart V3 and Visual Basic.

I would like to use the Graphics3D.RotateLabel method to put a string next to the axis labels of the right axis (see http://www.teechart.net/support/viewtopic.php?t=7036 for the reason).

The code would be:

Code: Select all

TChart1.Graphics3D.RotateLabel(myX, myY, myZ, "My Title", 90.0)
I haven't been able to figure out the right combination of properties and methods from TChart1.Axes.Right.Labels and TChart1.Graphics3D that will give me myX, myY and myZ such that "My Title" ends up next to the axis labels when the chart is rotated. I tried

Code: Select all

TChart1.Graphics3D.RotateLabel(TChart1.Axes.Right.Labels.Right, TChart1.Axes.Right.Labels.Bottom, 0, "My Title", 90.0)
but (of course) that only works when the chart isn't rotated (TChart1.Aspect.Rotation = 0). Can anyone help?

Jay

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 Dec 12, 2007 10:15 am

Hi Jay,

It is difficult getting accurate results converting 2D screen coordinates to real 3D coordinates as neither GDI+ nor GDI provide methods for such operations. However, you can try doing something like the code below in the OnAfterDraw event using legend's position as a reference.

Code: Select all

		private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
		{
			int zPos;

			if (tChart1.Aspect.Orthogonal)
			{
				zPos = 0;
			}
			else
			{
				zPos = tChart1.Axes.Depth.IEndPos;	
			}

			g.RotateLabel(tChart1.Legend.Left - 20, tChart1.Axes.Right.Labels.Bottom, zPos, "My Title", 90.0);
		}
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

JayG
Newbie
Newbie
Posts: 71
Joined: Mon Sep 04, 2006 12:00 am

X,Y,Z from Axis Labels

Post by JayG » Wed Dec 12, 2007 4:16 pm

There must be some way to figure it out, because you are drawing the axis labels next to the axis, and they are drawn at the correct location when the chart is rotated. What steps do you use to position the axis labels correctly? I should be able to use the same steps to place my own string.

Also, I'm not using the legend in my application.

Jay

JayG
Newbie
Newbie
Posts: 71
Joined: Mon Sep 04, 2006 12:00 am

X,Y,Z from Axis Labels

Post by JayG » Wed Dec 12, 2007 10:44 pm

The closest I've been able to get so far is this:

Code: Select all

myX = TChart1.Axes.Right.Position + TChart1.Axes.Right.MaxLabelsWidth + g.FontHeight + 5
myY = TChart1.Series(26).CalcYPosValue((TChart1.Axes.Left.Maximum + TChart1.Axes.Left.Minimum) / 2)
myZ = CInt(TChart1.Aspect.Width3D * TChart1.Axes.Right.ZPosition * 0.01)
TChart1.Graphics3D.RotateLabel(myX, myY, myZ, "My Title", 270.0)
The refernce to series 26 and the left axis min and max to assign a value to myY was simply a way of finding a point in the middle of the vertical axes. Series 26 is closest to the front of the graph, and uses the left axis.

This works well if the chart is only rotated <= about 50 degrees. However, the myX value would have to be increased gradually as the chart rotation increases above that. This is because the axis labels are a fixed width, but the RotateLabel method "decereases" the effect of the MaxLabelsWidth part of myX when the 3D calculation is performed. I don't know if that makes sense, but that's the only way I can think of to describe it. I may try to see if I can use some trig functions or something else to modify the x coordinate based on the chart's rotation. Actaully, now that I look at it again, if the chart is rotated 90 degrees, it wouldn't matter what myX was, "My Title" would always be drawn right next to the axis.

Does anyone have any more ideas?

Jay

Jay

JayG
Newbie
Newbie
Posts: 71
Joined: Mon Sep 04, 2006 12:00 am

X,Y,Z from Axis Labels

Post by JayG » Fri Dec 14, 2007 4:42 pm

I finally had some time to look at the TeeChart source. I now have a better understanding of how RotateLabel works (it is overloaded, with or without a Z parameter) and I also realized there is a Calc3DPos method. So here is what seems to work (in the AfterDraw event handler):

Code: Select all

SX = TChart1.Axes.Right.Position
If TChart1.Axes.Right.Labels.Align = Steema.TeeChart.AxisLabelAlign.Default Then
    SY = TChart1.Series(26).CalcYPosValue((TChart1.Axes.Left.Maximum + TChart1.Axes.Left.Minimum) / 2) - (TChart1.Graphics3D.TextWidth(TChart1.Axes.Right.Title.Text) / 2)
    TChart1.Graphics3D.Calc3DPos(SX, SY, CInt(TChart1.Aspect.Width3D * TChart1.Axes.Right.ZPosition * 0.01))
    TChart1.Graphics3D.RotateLabel(SX + TChart1.Axes.Right.MaxLabelsWidth + (g.FontHeight / 2), SY, TChart1.Axes.Right.Title.Text, 270.0)
Else
    SY = TChart1.Series(26).CalcYPosValue((TChart1.Axes.Left.Maximum + TChart1.Axes.Left.Minimum) / 2) + (TChart1.Graphics3D.TextWidth(TChart1.Axes.Right.Title.Text) / 2)
    TChart1.Graphics3D.Calc3DPos(SX, SY, CInt(TChart1.Aspect.Width3D * TChart1.Axes.Right.ZPosition * 0.01))
    TChart1.Graphics3D.RotateLabel(SX - TChart1.Axes.Right.MaxLabelsWidth - (g.FontHeight / 2), SY, TChart1.Axes.Right.Title.Text, 90.0)
End If
Note that I am using the existing TeeChart properties fo the title text, zposition, and alignment, but I have the Title.Visible property set to false. Also, as I mentioned before, the reference to series 26 to find the y position is simply to find the midpoint of the vertical axes. I will eventually change that to something more generic in case there aren't 27 series on the chart.

I thought about changing the TeeChart source for displaying the axis title and recompiling, but I don't thave the full version of Visual Studio on my PC, just Visual C# 2008 Express Edition (it can't handle the Pocket2005 part of the project). Is there any possibility that Steema could change the code for displaying the axis title to include these (or similar) modifications in a future release?

Jay

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

Post by Narcís » Tue Dec 18, 2007 12:34 pm

Hi Jay,

You can use csc.exe which comes free with the .NET framework SDK http://msdn2.microsoft.com/en-us/library/78f4aasd.aspx
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