Macro (SVB) Programs Example - Accessing and Customizing Graphs

This program illustrates how to access Statistica Graphs using different methods and how to create and customize them.

Sub MainCustomizedLinePlot
End Sub 
Sub OpenFromFile
'open graph from predefined disk file 
Dim g As Graph Set g = Graphs.Open ("p:\data\3d.stg") 
g.Visible = TrueEnd Sub Sub AccessTopGraph
'do something with top most graph 
Dim g As Graph Set g = ActiveGraph 
MsgBox "Active graph: " + g.Path + g.Name
End Sub 
Sub SimpleLinePlot
'create a simple line plot from Active Dataset 
Dim a As Analysis Set a = Analysis (sc2dLinePlots) 
a.Dialog.Variables = 6 
Set g = a.Dialog.Graphs(1) g.Visible = True
End Sub 
Sub LinePlotWithOptions
'create a multiple line plot from Active Dataset 
'set reverse axis and turn off default title 
Dim a As Analysis Set a = Analysis (sc2dLinePlots) 
Dim lp As LinePlot2D Set lp = a.Dialog 
'set plot type and variables 
lp.GraphType = scLineMultiplePlot 
lp.Variables = "6 7" 
'change options 
lp.Options.DisplayDefaultTitle = False 
lp.Options.XYAxisPosition = scAxisReverse 
lp.Graphs(1).Visible = True
End Sub 
Sub CustomizedLinePlot
'create a customized line plot from Active 
Dataset Dim a As Analysis 
Set a = Analysis (sc2dLinePlots) 
a.Dialog.GraphType = scLineMultiplePlot 
a.Dialog.Variables = "6 7 8" 
'grab graph object 
Set g = a.Dialog.Graphs(1) 
Dim bFirstLevel, bSecondLevel, bThirdLevel, bFourthLevel As Boolean 
bFirstLevel = True 
bSecondLevel = True 
bThirdLevel = True 
bFourthLevel = True 
'customize titles, background 
If bFirstLevel Theng.Titles(1) = "New (better?) title" 
g.GraphWindow.Background.Color = RGB (255,255,0)
End If 
' get graph content 
Dim l As Layout2D Set l = g.Content 
'customize plots: axis title and set line set to solid 
If bSecondLevel Then 
'set y axis manual scale
Dim y As Axis2D 
Set y = l.Axes.YAxis y.SetManualRange(0, 20) 
y.RangeMode = scgManualRange 
y.StepSize = 5 y.StepMode = scgManualStep 
' set x axis title and turn off gridlines 
Dim x As Axis2D 
Set x = l.Axes.XAxis 
x.Title = "Sequential cases" 
x.DisplayMajorGridLine = False 
' customize gridlines on y axis 
y.MajorGridLine.ForegroundColor = RGB(0,0,0) 
y.MajorGridLine.Type = scgSolid
End If 
Dim pp As Plots2D 
Set pp = l.Plots 
If bThirdLevel Then 
' plot customizations
' line patterns pp.Item(1).Line.Type = scgSolid 
pp.Item(2).Line.Type = scgSolid 
pp.Item(3).Line.Type = scgSolid 
' make third plot stand out from the rest 
pp.Item(3).Marker.Size = 6 
pp.Item(3).Line.Weight = .75
End If 
If bFourthLevel 
Then 
' changing plot variable values 
' we will set values <= 0 to mean of previous and next value
Dim v As Variable 
Set v = pp.Item(3).Variable(2) 
For vind = 2 To v.ValuesCount() - 1If v.Value(vind) <= 0 Then
v.Value(vind) = (v.Value(vind-1) + v.Value(vind+1))/2
End If
Next vind
End If g.Visible = TrueEnd Sub