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.


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)
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
l = g.Content

' Customize plots: axis title and set line set to solid.

If bSecondLevel Then

'set y axis manual scale
y As Axis2D
y = l.Axes.YAxis
y.RangeMode = scgManualRange
y.StepSize = 5
y.StepMode = scgManualStep

' Set x axis title and turn off gridlines.

Dim x As Axis2D
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

pp As Plots2D
pp = l.Plots

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
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) + _

End If

Next vind

End If
g.Visible = True


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: