This article contains Grapher sample script that shows how to create a bar chart graph, add a second adjacent bar chart, and change some properties.
To run this script:
- Click here to download the BAS file: Bar Chart-Adjacent.BAS
- Click Automation | Scripts | Run, select the BAS file from your downloads directory, and click Open.
- Copy the script below.
- Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
- Press Ctrl+A to select all of the existing lines in the Script Manager and then press DELETE.
- Press Ctrl+V to paste it into the Script Manager.
- Click the Start/Resume icon () in the Script Manager.
Sub Main 'This script shows how to create two bar charts and make them adjacent to each other 'Declares objects Dim GrapherApp, Plot, Graph, BarChart1 As Object 'Creates an instance of the Grapher Application called "GrapherApp" Set GrapherApp = CreateObject("Grapher.Application") 'Makes Grapher Visible GrapherApp.Visible = True 'Creates a plot document in Grapher called "Plot" Set Plot = GrapherApp.Documents.Add(grfPlotDoc) 'Create a bar chart Set Graph = Plot.Shapes.AddBarChartGraph(GrapherApp.Path+"\samples\bar chart orientations.dat",,,) 'Add a second bar chart to the graph Graph.AddBarChart(GrapherApp.Path+"\samples\bar chart orientations.dat",,3,) 'Assign the first bar chart to the object name BarChart1 Set BarChart1 = Graph.Plots.Item(1) 'Set the bars to use only rows 1-10 BarChart1.AutoLastRow = False BarChart1.LastRow = 10 'Change the first bar chart to blue fill BarChart1.Fill.foreColor(grfColorNavyBlue) 'Make the bar charts adjacent BarChart1.Stacked=False 'Turns off the axes titles Graph.Axes.Item(1).title.text = "" Graph.Axes.Item(2).title.text = "" 'Sets a custom x axis maximum value Graph.Axes.Item(1).AutoMax = False Graph.Axes.Item(1).Max = 10.5 End Sub
Updated November 18, 2017