' This example demonstrates how To Format an Axis Object using the Axis Element Object. ' MyIGraph must be a valid ISpssIGraph object variable. ' Raynald Levesque rlevesque@videotron.ca Const SpssIGraphX1 As Integer = 0 Const SpssIGraphY As Integer = 1 Const SpssIGraphGridLineAtMajorTicks As Integer = 0 Const spssAxisLabelAllCategories As Integer = 2 Const spssAxisLabelHorizontal As Integer = 1 Const SpssIGraphTickFormatFloating As Integer = 0 Const vbBlack As Long = 16777215 Public dblThick As Double, blnGrid As Boolean, strGraphName As String Public intMaxX As Integer, intMaxY As Integer, intDeltaX As Integer, intDeltaY As Integer Option Explicit Sub main Dim objOutputDoc As ISpssOutputDoc Dim objOutputItems As ISpssItems Dim objOutputItem As ISpssItem Dim MyIgraph As ISpssIGraph Dim intItemCount As Integer, intItemType As Integer, strLabel As String, intCtr As Integer Dim strInput As String Set objOutputDoc = objSpssApp.GetDesignatedOutputDoc Set objOutputItems = objOutputDoc.Items() ' get parameters from syntax strInput = objSpssApp.ScriptParameter(0) ParseInput(strInput) 'intDeltaX = 1 'intDeltaY = 4 intItemCount = objOutputItems.Count() For intCtr=1 To intItemCount - 1 Set objOutputItem = objOutputItems.GetItem(intCtr) intItemType = objOutputItem.SPSSType() strLabel = objOutputItem.Label 'Find graphics to be formated then call subs to do the job If strLabel = strGraphName Then Set MyIgraph = objOutputItem.Activate() Call DoTicks(MyIGraph, SpssIGraphX1, intDeltaX) Call DoTicks(MyIGraph, SpssIGraphY, intDeltaY) Call DoGrids (MyIgraph) objOutputItem.Deactivate End If Next End Sub '****************************** ' This example demonstrates how to set the major Ticks ' situated on the X and Y-Axis using the Dimension Object. ' MyIGraph must be a valid ISpssIGraph object, and ' DimensionSlot is the slot you want to format Sub DoTicks(MyIGraph As ISpssIGraph, DimensionSlot As Integer,intDelta As Integer) ' Sets the major Ticks Dim MyVariableManager As ISpssIGraphVariablesMgr Dim MyScaleDimension As ISpssIGraphDimension Dim DimensionVariableName() As String Dim iTick As Integer, intIndex As Integer, intMaxValue As Integer Set MyVariableManager = MyIGraph.VariablesMgr ' First we need to make sure that the slot contains at least one variable and get the name ' of the variable(s). GetAssigned returns False if the specified slot does not contain a variable If MyVariableManager.GetAssigned(DimensionSlot, DimensionVariableName) = True Then ' Next, check to see if the first variable is a scale variable. If MyVariableManager.Categorical(DimensionVariableName(0)) = False Then ' If it's a scale variable, retrieve its dimension object Set MyScaleDimension = MyIGraph.VariablesMgr.GetDimension(DimensionSlot) With MyScaleDimension .TickFormat = SpssIGraphTickFormatFloating .NumberOfMajorTicksAutomatic =False intMaxValue=.ScaleMax intIndex = 0 For iTick=0 To intMaxValue + intDelta Step intDelta .SetMajorTickLabel(intIndex,CStr(Fix(iTick))) Debug.Print intIndex & " " & .GetMajorTickLabel(intIndex) intIndex = intIndex + 1 Next .NumberOfMajorTicks = intIndex - 1 End With ' Always redraw the graph after making changes MyIGraph.Redraw End If End If End Sub '************************************** Sub DoGrids(MyIgraph As ISpssIGraph) ' Declare the axis objects Dim MyYAxis As ISpssIGraphAxis Dim MyXAxis As ISpssIGraphAxis Dim MyArea As ISpssIGraphDataRegion Set MyArea = MyIgraph.GetDataRegion 'Set graph border to a dark line MyArea.GetArea.BorderTransparent = 0 MyArea.GetArea.BackgroundColor = vbBlack MyArea.GetArea.BorderWeight = dblThick ' Retrieve the Graph's Y-Axis Set MyYAxis = MyIGraph.GetAxis(0) With MyYAxis ' Turn on the grid lines and position them at major ticks .GridLines = blnGrid .GridLinesLocation = SpssIGraphGridLineAtMajorTicks .LabelFrequency = spssAxisLabelAllCategories .LabelOrientation = spssAxisLabelHorizontal End With ' Retrieve the Graph's X-Axis Set MyXAxis = MyIGraph.GetAxis(1) With MyXAxis ' Turn on the grid lines and position them at major ticks .GridLines = blnGrid .GridLinesLocation = SpssIGraphGridLineAtMajorTicks .LabelFrequency = spssAxisLabelAllCategories .LabelOrientation = spssAxisLabelHorizontal End With ' Always redraw the graph after making changes MyIGraph.Redraw End Sub '-------------------------------- Sub ParseInput(strInput As String) ' Parse the input string into its components Dim intTemp1 As Integer, intTemp2 As Integer 'StrErr = "Error while parsing input:" intTemp1 =InStr(strInput,",") strGraphName=Mid(strInput,1,intTemp1-1) intTemp2 =InStr(intTemp1+1,strInput,",") intDeltaX =CInt(Mid(strInput,intTemp1+1,intTemp2-intTemp1-1)) intTemp1 =intTemp2 intTemp2 =InStr(intTemp1+1,strInput,",") intDeltaY =CInt(Mid(strInput,intTemp1+1,intTemp2-intTemp1-1)) intTemp1 =intTemp2 intTemp2 =InStr(intTemp1+1,strInput,",") blnGrid =CBool(Mid(strInput,intTemp1+1,intTemp2-intTemp1-1)) dblThick =CDbl(Mid(strInput,intTemp2+1,Len(strInput)-intTemp1)) End Sub