Create multi-colored bar chart graphs in Grapher via automation

To create a bar chart graph, where each bar is a different color (determined by a color table):

  1. Click here to download the BAS file: Bar Chart - MultiColor.BAS
  2. Click Automation | Scripts | Run, select the BAS file from your downloads directory, and click Open.

OR:

  1. Copy the script below.
  2. Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
  3. Press Ctrl+A to select all of the existing lines in the Script Manager and then press DELETE.
  4. Press Ctrl+V to paste it into the Script Manager.
  5. 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
'object and assigns it to the variable named "GrapherApp"
 Set GrapherApp = CreateObject("Grapher.Application")

'Makes Grapher Visible
 GrapherApp.Visible = True

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

'Create a bar chart and graph
 Set Graph =  Plot.Shapes.AddBarChartGraph(GrapherApp.Path+"\samples\bar chart orientations.dat",,,)

'Assign the 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 'Set the bar fill to the default color table BarChart1.UseColorTable = True '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

'Turns on the color table legend
BarChart1.ShowColorTableLegend=True

End Sub

 

Updated March 2020

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.