Macro (SVB) Programs Example - Customizing Graphs

The customization of graphs proceeds in much the same way as the customization of spreadsheets. After a Graph object is created, various properties and methods are available to customize practically all aspects of the display. Here is an example program:

' This program illustrates how create and customize 
' different aspects of Statistica Graphs. Sub Main

Dim a As Analysis

' Create the 2D Line Plot analysis object; you 
' may have to edit the path name for the input data 
' file (Spreadsheet), to match the installation of 
' Statistica on your computer.

Dim s As New Spreadsheet
Set s = Spreadsheets.Open _ (Path & "\Examples\DataSets\Exp.sta")
Set a = Analysis (sc2dLinePlots,s) a.Dialog.GraphType = scLineMultiplePlot a.Dialog.Variables = "6 7 8"

'Retrieve the first graph object from the collection.
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 Then
g.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.MajorGridLine.ForegroundColor.Transparent = True

' 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() - 1

If 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 = True

s.Close

End Sub

This program will create a 2D line plot, and customize various aspects of this plot. The resulting plot will look something like this: