Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Measurement Studio .NET Scattergraph labels

support@ni.com
09/25/2003 10:34
Please respond to support

To: mefitzpatrick@mmm.com
cc:
Subject: Important: Please Resubmit Your Support Request


Thank you for contacting National Instruments! This is an automatic
response to the e-mail that you sent to support@ni.com. To give you the
highest level of service and the fastest resolution time, we ask that you
submit all requests for e-mail support through our Request Support page at
http://www.ni.com/ask. Your original question is included below.

Our Request Support page saves you time by remembering your system
information and allowing us to ask important configuration questions up
front. This eliminates the need for multiple clarification e-mails and
makes the support process more efficient on both sides. After you have
submitted your new request, subsequent correspondence for that request is
handled through e-mail.

If you do not have access to the Web, as an alternative you may contact us
via phone. For contact details, please refer to your product or service
agreement literature.

If you have an existing e-mail reference number, or you believe that you
have received this message in error, then please contact us at
webmaster@ni.com.

Best Regards,

National Instruments Technical Support Team


----------------------------------------
----------------------------------------
I looked at the sample and it does exhibit the problem. Simply place the Y2
axis on the right side of the graph.

Where can I get a GDI font with a vertical rotation? Will I be able to use
this font as a X axis label so that the labels are also vertical and do not
over write each other?


-----Original Message-----
From: support@ni.com [mailto:support@ni.com]
Sent: Monday, September 22, 2003 9:34 AM
To: ni@codeinsight.com
Subject: Re: (Reference#3266-RDX594) Measurement Studio .NET
Scattergraph labels



Note: Your reference number is included in the Subject field of this
message. It is very important that you do not remove or modify this
reference number, or your message may be returned to you.


Michael,

I created a ScatterGraph, and by default, my two Y-Axis seem to both be
readable in the same direction (parallel to each other), so I'm uncertain
as to what behavior you are seeing! Attached is my code in vbtest.zip. If
this isn't what you mean, please let me know.

The GdiVerticalFont property is set based on the type of Font that you've
applied to the Axis caption. If you have a GDI-rotated font, it should
automatically set this property approrpriately.

If you have any more qurestions, please let me know!



Regards

David McClelland
Applications Engineer
National Instruments
http://www.ni.com/support

----------------------------------------------------------------------------


--

Problem Description :
I am creating Scattergraphs using the MS.Net control. I placed 2 Y Axes on
the graph. The captions on the Y axes are different orientations, that is,
it is neccessay to rotate the paper 180 degrees to read one from the other.
How can I get the Y axis captions to both read the same direction?

Also, how do I use a GDI rotated font on the axis? Example:
MyXAxis.CaptionFont.GdiVerticalFont
This is so that I can use the labels on the X axis and not have them write
over each other.

(This may seem trivial but the customer asked for it!)
NI Software :
Measurement Studio for Visual Basic version 7.0
NI Hardware :
None device
Driver Version :
OS :
Windows 2000
Customer Information :
Michael Fitzpatrick
Volt
US
ni@codeinsight.com
Ph: (
707
)
527-0947
0 Kudos
Message 1 of 2
(3,922 Views)
There is not currently a property that you can set on the axis to change the direction that the caption faces, but for now you can use the graph's custom drawing features to implement this yourself. Below is a sample method that accepts Graphics and YAxis parameters and draws the specified YAxis on the Graphics surface such that the YAxis caption faces the same direction it does when the YAxis is on the left-hand side. One way you could call this method is in the Paint event of the graph. For example, if you added a ScatterGraph to a form in a new Windows Forms project and added a second YAxis to the graph, the Paint event handler for the ScatterGraph would look like this:

Private Sub OnScatterGraphPaint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles ScatterGraph1.Paint
DrawAxisWithLeftRotatedLabel(e.Graphics, YAxis2)
End Sub

Here is the method that handles the YAxis drawing:

' Add these Imports to the top of the source file that contains the method
Imports System.Drawing.Drawing2D
Imports NationalInstruments
Imports NationalInstruments.UI

' ...

Shared Sub DrawAxisWithLeftRotatedLabel(ByVal g As Graphics, ByVal yAxis As YAxis)
If g Is Nothing Then
Throw New ArgumentNullException("g")
End If

If yAxis Is Nothing Then
Throw New ArgumentNullException("yAxis")
End If

If (yAxis.Owner Is Nothing) Or (Not TypeOf yAxis.Owner Is IXYGraph) Then
Throw New ArgumentException("yAxis")
End If

Dim graph As IXYGraph = DirectCast(yAxis.Owner, IXYGraph)
Dim axisBounds As Rectangle = yAxis.GetBounds(YAxisPosition.Right)

' Clear the right Y axis that was drawn.
Dim axisBrush As Brush
Try
axisBrush = New SolidBrush(graph.BackColor)
g.FillRectangle(axisBrush, axisBounds)
Finally
If Not axisBrush Is Nothing Then
axisBrush.Dispose()
End If
End Try

' Draw the right Y axis again but without the label.
Dim clone As YAxis = DirectCast(yAxis.Clone(), YAxis)
clone.Caption = String.Empty
clone.Draw(New ComponentDrawArgs(g, axisBounds), YAxisPosition.Right)

' Draw the right Y axis label rotated out instead of in.
Dim state As GraphicsState = g.Save()
Try
' First, rotate the graphics surface for drawing and calculate the rotated bounds.
g.TranslateTransform(0, graph.Height)
g.RotateTransform(-90)
axisBounds = New Rectangle(graph.Height - axisBounds.Bottom, axisBounds.X, axisBounds.Height, axisBounds.Width)

' Next, calculate where to draw the new label.
Dim labelSize As SizeF = g.MeasureString(yAxis.Caption, yAxis.CaptionFont)
Dim labelX As Single = Math.Abs(axisBounds.X + (axisBounds.Width - labelSize.Width) / 2)
Dim labelY As Single = axisBounds.Bottom - labelSize.Height - 2

' Finally, draw the rotated label.
Dim labelBrush As Brush
Try
labelBrush = New SolidBrush(yAxis.CaptionForeColor)
g.DrawString(yAxis.Caption, yAxis.CaptionFont, labelBrush, labelX, labelY)
Finally
If Not labelBrush Is Nothing Then
labelBrush.Dispose()
End If
End Try
Finally
g.Restore(state)
End Try
End Sub

Hope this helps.

- Elton
Message 2 of 2
(3,922 Views)