axis text example

axis text example

philbrierley's picture

I have a 3d plot and want to lable the axes - not with values but with the field name - ie Axis1 Axis2 & Axis3.

I'm struggling to follow the help files to achieve this.Is there any sample VB code that will show me how to do this?

The bulk of my code to date is below...

Private Sub Plot(bChngViewPoint As Boolean)
Dim dset2 As IAvDataset
Dim dset1 As IAvDataset
Dim graph As IAvGraph3D
Dim xyzPlot1 As IAvXYZPlot
Dim xyzPlot2 As IAvXYZPlot

'Define three sections for the X, Y, and Z columns
Dim secX As IAvSection
Dim secY As IAvSection
Dim secZ As IAvSection
If bChngViewPoint = False Then Call getViewPoint
m_bViewerCreated = False
Set m_root = New AvGroup
'Create an AvDataset for M
Set dset1 = m_root.Datasets.CreateDataset("dset1")
Call dset1.WriteData(m)
'Create an AvDataset for N
Set dset2 = m_root.Datasets.CreateDataset("dset2")
Call dset2.WriteData(n)

Set secX = dset1.Dataspace.Sections.CreateNewSection("X")
secX.start(1) = 0
secX.End(1) = 0
secX.start(2) = 0
secX.End(2) = UBound(m, 2) '- 1
Set secY = dset1.Dataspace.Sections.CreateNewSection("Y")
secY.start(1) = 1
secY.End(1) = 1
secY.start(2) = 0
secY.End(2) = UBound(m, 2) ' - 1
Set secZ = dset1.Dataspace.Sections.CreateNewSection("Z")
secZ.start(1) = 2
secZ.End(1) = 2
secZ.start(2) = 0
secZ.End(2) = UBound(m, 2) ' - 1
'Do the same for dset2
Set secX = dset2.Dataspace.Sections.CreateNewSection("X")
secX.start(1) = 0
secX.End(1) = 0
secX.start(2) = 0
secX.End(2) = UBound(n, 2) ' - 1
Set secY = dset2.Dataspace.Sections.CreateNewSection("Y")
secY.start(1) = 1
secY.End(1) = 1
secY.start(2) = 0
secY.End(2) = UBound(n, 2) ' - 1
Set secZ = dset2.Dataspace.Sections.CreateNewSection("Z")
secZ.start(1) = 2
secZ.End(1) = 2
secZ.start(2) = 0
secZ.End(2) = UBound(n, 2) ' - 1

'Create a graph
Set graph = m_root.Graphs.CreateGraph3D("xyzgraph")
With graph
'Show the graph border
.Border.Visible = True
' .Border.Color = m_root.Context.RGBA(200, 0, 100, 255)

'Set the Origin and Size of the graph transform
.Transform.Origin(AV_XCOORD) = m_dMinX
.Transform.size(AV_XCOORD) = m_dMaxX - m_dMinX
.Transform.Origin(AV_YCOORD) = m_dMinY
.Transform.size(AV_YCOORD) = m_dMaxY - m_dMinY
.Transform.Origin(AV_ZCOORD) = m_dMinZ
.Transform.size(AV_ZCOORD) = m_dMaxZ - m_dMinZ
End With
'Create first XYZPlot
Set xyzPlot1 = graph.Plots.CreatePlot("xyzplot1", AV_XYZPLOT)
With xyzPlot1
.Transform.Inherit = True
.XSource = "/dset1@X"
.YSource = "/dset1@Y"
.ZSource = "/dset1@Z"
.GraphState.LineStyle = AV_NO_LINE
.Marker.Visible = True
.Marker.MarkerType = AV_FILLED_CIRCLE_MARKER
.Marker.size = markerSize
.Marker.Color = m_root.Context.RGBA(255, 0, 0, 255)
End With
'Create second XYZPlot
Set xyzPlot2 = graph.Plots.CreatePlot("xyzplot2", AV_XYZPLOT)
With xyzPlot2
.Transform.Inherit = True
.XSource = "/dset2@X"
.YSource = "/dset2@Y"
.ZSource = "/dset2@Z"
.GraphState.LineStyle = AV_NO_LINE
.Marker.Visible = True

.Marker.MarkerType = AV_FILLED_CIRCLE_MARKER
.Marker.size = markerSize
.Marker.Color = m_root.Context.RGBA(0, 255, 0, 255)
End With

'Point the Graph control to our newly created graph
AvGraphCtl1.root = m_root
AvGraphCtl1.GraphPath = "graph:/xyzgraph"
'AvGraphCtl1.ViewerMode = AV_FIXED_VIEWER

Call setViewPoint
Call checkVis
End Sub

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Community Admin's picture

You'll want to create three caption objects with the "Text" property of the captions set to the labels you want. In caption.Position set one of the "Size" values to 0 to get the caption to align with the other two axes. E.g. if caption.Size(AV_ZCOORD) = 0, then the caption will lie in the X/Y plane.

philbrierley's picture

Sorry, I'm getting nowhere with this. What am I missing from my code below - no caption is displayed.


Private Sub labelAxis()

Dim graph As IAvGraph3D
Dim captions As IAvCaptions
Dim captionX As IAvCaption

Set graph = m_root.Graphs(1)
Set captions = graph.captions
Set captionX = captions.CreateCaption("X")

With captionX
.Transform.Inherit = True
.Text = "This is the x-axis"
.AutoSize = True
.Position.size(AV_XCOORD) = 0
.Border.Visible = True
End With

End Sub

Community Admin's picture


You need to set two of the position values to be non-zero. See the code below. Also I turned off the Inherit property so that TextStart and FontSize aren't dependent on the graph transform.
Code:

With captionX
    .Transform.Inherit = False
    .Text = "This is the x-axis"
    .AutoSize = True
    .Border.Color = m_root.Context.RGBA(0, 255, 0, 255)
    .Position.Size(AV_XCOORD) = 1.5
    .Position.Size(AV_YCOORD) = 0#
    .Position.Size(AV_ZCOORD) = 0.2 
    .Border.Visible = True
End With



Message Edited by jlreadey on 10-04-2005 08:33 AM

philbrierley's picture

I'd already tried all this with no luck.

Did you actually get it to work yourself for a 3d plot? If so can you please post the project.

On another point, is it possible to get the 3d plot to automatically rotate in random directions without having to use the mouse, or can the rotation be programmed?

Phil

Community Admin's picture

Here's a project that displays a caption. There's also a checkbox that will cause the plot to rotate. Let me know if you run into any problems. I'm on the road this week, so I haven't had a chance to test this with the eval kit, but it should work.

philbrierley's picture

Hi again!

I've modified the demo xyz plot to demonstratea few more features. The project is attached.

There are 2 things I'm stuck on.

1. Every time the graph is replotted or rotated it seems to plot twice, in slightly offset positions. This is even more noticable when you look at the size of the font for the axis labels I've added. They significantly change in size. How can this be prevented?

2. I cannot get the z-axis label to print vertically up the axis, whatever rotation I use.

Also, in your previous attached project I couldn't get the auto rotate to do anything.

I sure would appreciate you modifying the project to show how to solve these problems. I also think it would be good if we allow this project to grow to demonstrate more of the features that are available. I'm happy to put the work in. Sample code is always much more helpful than any manual. Also VB6 should be easily 'readable' to use the ideas in the other languages.

Community Admin's picture

Thanks for the example. Fixing the two problems you found may require changes in avlib.dll. I'll investigate and let you know what I find out.

Login to leave a comment.