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