HOW TO
Instructions provided describe how to insert a data graph into ArcMap's page layout.
Note:
The following procedure does not apply to ArcGIS version 9.2 and higher.
Note:
Code in the project's ThisDocument code module only runs in the current map document. To store the code in all the map documents, open the Normal.mxt ThisDocument code module instead.
Code:
Sub InsertGraph()
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
'Qi for IDataGraphs
Dim pDataGraphs As IDataGraphs
Set pDataGraphs = pDoc
'Name of the graph to insert
Dim strGraphName As String
strGraphName = "Graph of Sw"
'Loop through the data graphs
'and find the one to insert.
Dim pDataGraph As IDataGraph
For i = 0 To pDataGraphs.Count - 1
'Exit the loop once the correct graph
'is found.
If pDataGraphs.Item(i).Name = strGraphName Then
Set pDataGraph = pDataGraphs.Item(i)
Exit For
End If
Next i
'Check to make sure a graph is found.
If pDataGraph Is Nothing Then
MsgBox "No graph named " & strGraphName & " exists"
End If
'Get the DataGraphElement.
Dim pDGElem As IDataGraphElement
Set pDGElem = New DataGraphElement
Set pDGElem.DataGraph = pDataGraph
Dim pElem As IElement
Set pElem = pDGElem
'Insert the graph into the page layout.
Dim pGc As IGraphicsContainer
Set pGc = pDoc.PageLayout
'Create an envelope that defines
'the location to add the data graph.
Dim pEnv As IEnvelope
Set pEnv = New Envelope
'Set xmin, xmax, ymin, ymax.
pEnv.XMin = 0.924503
pEnv.XMax = 4.343488
pEnv.YMin = 0.785541
pEnv.YMax = 2.949117
pElem.Geometry = pEnv
'Add the graph to the layout's graphic container.
pGc.AddElement pElem, 0
'Refresh the view.
pDoc.ActiveView.Refresh
End Sub
Get help from ArcGIS experts
Download the Esri Support App