Follow

How do I create a wind chart with a Grapher script?

This article contains Grapher sample script that shows how to create a wind chart and how to change all the methods and properties.

 

To run this script:

  1. Copy the script below, or click here to download the BAS file: AutoWindChart.BAS.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Grapher 12\Scripter.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press Delete.
  5. If you copied this script, press Ctrl+V to paste it into Scripter. If you downloaded it, click File | Open, select the BAS file from your downloads directory, and click Open.
  6. Click Script | Run to run the script.
     

*********

Sub Main
'This script shows all the methods and properties of a wind chart

'Declares GrapherApp as an object
 Dim GrapherApp As Object

'Creates an instance of the Grapher Application
'object and assigns it to the variable named "GrapherApp"
 Set GrapherApp = CreateObject("Grapher.Application")

'Makes Grapher visible
 GrapherApp.Visible = True

'Open existing windchart.gpj file
 Set existing = GrapherApp.Documents.Open(GrapherApp.Path+"\Samples\windchart.gpj")

'Display worksheet
 existing.Shapes.Item(1).Plots.Item(1).DisplayWorksheet

'Save the GPJ data to a DAT file for use in this script
 Set windchartWks1dat = GrapherApp.Documents.Active
 windchartWks1dat.SaveAs(GrapherApp.Path+"\Samples\winddata.dat",,wksFileFormatDat)

'Close existing graph and data
 windchartWks1dat.Close
 existing.Close(grfSaveChangesNo)

'Declares Plot as an object
 Dim Plot As Object

'Creates a plot document in Grapher and
'assigns it to the variable named "Plot"
 Set Plot = GrapherApp.Documents.Add(grfPlotDoc)

'Declares Graph1 as an object
 Dim Graph1 As Object

'Creates a graph and assigns it to the variable named "Graph1"
 Set Graph1 = Plot.Shapes.AddWindChartGraph(GrapherApp.Path+ "\samples\winddata.dat")

'Declares WindChart as an object
 Dim WindChart As Object

'Set WindChart to the first plot on the Graph1 graph
 Set WindChart = Graph1.Plots.Item(1)

'Set the column used for speed (can
'also be set in AddWindChartGraph)
 WindChart.speedCol = 2
'return the column used for speed
 Debug.Print "Speed column = "; WindChart.speedCol

'Set the column used for direction (can
'also be set in AddWindChartGraph)
 WindChart.dataCol = 1
'return the column used for direction
 Debug.Print "Direction column = "; WindChart.dataCol

'Add a legend to the graph
 WindChart.DisplayLegend = True

'Set the angular size of automatic bins to 45 degrees
 WindChart.binSize = 45

'Turn auto arc size off for automatic bins
 WindChart.ArcSizeAuto = False

'Set the arc size of the automatic bins to 10 degrees
 WindChart.ArcSize = 10

'Set the starting place for the bins
 WindChart.StartAt = 22.5

'Delete existing speed bins
 WindChart.DeleteSpeedBin(1)
 WindChart.DeleteSpeedBin(1)
 WindChart.DeleteSpeedBin(1)
 WindChart.DeleteSpeedBin(1)

'Create new speed bins
 WindChart.AddSpeedBin(0,2,True)
 WindChart.AddSpeedBin(2,4)
 WindChart.AddSpeedBin(4,6)
 WindChart.AddSpeedBin(6,8)
 WindChart.AddSpeedBin(8,10)
 WindChart.AddSpeedBin(10,12)
 WindChart.AddSpeedBin(12,14)
 WindChart.AddSpeedBin(14,16)
 WindChart.AddSpeedBin(16,18)
 WindChart.AddSpeedBin(18,18,,True)

Wait 2

'Turn off the automatic binning for direction
 WindChart.AutoBin = False

'Add new custom bins
 WindChart.AddBin(0,1)
 WindChart.AddBin(15,20)
 WindChart.AddBin(40,60)
 WindChart.AddBin(60,80)
 WindChart.AddBin(80,100)
 WindChart.AddBin(100,120)
 WindChart.AddBin(120,140)
 WindChart.AddBin(140,160)
 WindChart.AddBin(160,180)
 WindChart.AddBin(180,200)
 WindChart.AddBin(200,220)
 WindChart.AddBin(220,240)
 WindChart.AddBin(240,260)
 WindChart.AddBin(260,280)
 WindChart.AddBin(280,300)
 WindChart.AddBin(300,320)
 WindChart.AddBin(320,340)
 WindChart.AddBin(340,360)

'Delete the first two bins and make new ones
 WindChart.DeleteBin(1)
 WindChart.DeleteBin(1)
 WindChart.AddBin(0,20)
 WindChart.AddBin(20,40)

'Display labels as frequency
 Debug.Print "Labels as frequency = "; WindChart.DisplayAsFreq
'True to display as frequency
 WindChart.DisplayAsFreq=True

'Display labels as percent - need
'to display as frequency first
 Debug.Print "Labels as percent = "; WindChart.DisplayAsPercent
 WindChart.DisplayAsPercent=True

'Change the second speed bin's color
 WindChart.SpeedBinFill(2).PatternName = "Solid"
 WindChart.SpeedBinFill(2).foreColor = grfColorLightBlueGreen

End Sub

 

Updated September 22, 2016

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.