1.7 Graphs

The GraphPage class is for working with a graph window. There is a GraphPage object for each graph window. A GraphPage object contains a collection of layers. Each of these layers is a GraphLayer object.

Accessing an Existing Graph

There are multiple ways to access an existing graph. The methods used are the same as those used for workbooks and matrix books.

You can access a graph by passing its name to the class constructor.

GraphPage grPg("Graph1");
if( grPg ) // if there is a graph named "Graph1"
    grPg.SetName("MyGraph1"); // rename the graph

The Project class contains a collection of all the graphs in the project. The following example shows how to loop through the collection and output the name of each graph.

foreach(GraphPage grPg in Project.GraphPages)
    out_str(grPg.GetName()); // output graph name

You can access a graph by passing its zero-based index to the Item method of the Collection class.

GraphPage grPg;
grPg = Project.GraphPages.Item(2);
if( grPg ) // if there is a 3rd graph
    out_str(grPg.GetName()); // output graph name

Deleting a Graph

All Origin C's internal classes are derived from the OriginObject class. This class has a Destroy method that is used to destroy the object. Calling this method on a graph will destroy the graph, all the layers in the graph, and all the graph objects on each layer.

GraphPage grPg;
grPg = Project.GraphPages.Item(0); // get first graph in project
if( grPg ) // if there is a graph
    grPg.Destroy(); // delete the graph
This section covers the following topics: