usingVB
Programmer
- Jan 1, 2009
- 8
Hi,
I'm trying to make a chart using VB code, however, I want to specify which fields are used for the X and Y axis.
I've found the following code, which works, but I'm not sure how to go about specifying X and Y axis fields. Any ideas?
Copied and pasted from website.....
Description:
This sample creates a very basic column chart. The code does not specify an X or Y axis field forcing the DataGraph object to automatically select these. For column charts, use IDataGraph::FieldSet1 to specify the y-axis and IDataGraphProperties::XAxisLabelField to specify the x-axis.
This sample provides an simple introduction to creating charts programmatically. There are many different interfaces and members that can be used to create a chart.
How to use:
Paste the code into VBA.
Select a map layer in the table of contents.
From the Macros dialog, run the CreateNewChart routine.
The new data graphy automatically selects two fields to use.
Public Sub CreateNewChart()
Dim pMxDoc As IMxDocument
Dim pDataGraph As IDataGraph
Dim pDataGraphProperties As IDataGraphProperties
Dim pGraphWindow As IDataGraphWindow
Dim pDataGraphs As IDataGraphs
Set pMxDoc = Application.Document
If pMxDoc.SelectedLayer Is Nothing Then Exit Sub
If Not TypeOf pMxDoc.SelectedLayer Is IFeatureLayer Then Exit Sub
'Create a new graph
Set pDataGraph = New DataGraph
'Set the default Table, DataGraph will select a default graph type and some fields
Set pDataGraph.Table = pMxDoc.SelectedLayer
'Specifically give the chart a name and title
pDataGraph.name = pMxDoc.SelectedLayer.name & " Chart"
Set pDataGraphProperties = pDataGraph 'QI
pDataGraphProperties.Title = "My Chart"
pDataGraphProperties.ShowXAxisLabels = True
pDataGraphProperties.ShowLegend = True
pDataGraphProperties.SubTitle = pDataGraph.FieldSet1 & " vs. " & pDataGraphProperties.XAxisLabelField
'Associate the data graph with a data graph window
Set pGraphWindow = New DataGraphWindow
Set pGraphWindow.DataGraph = pDataGraph
Set pGraphWindow.Application = Application
'Add the graph to the system
Set pDataGraphs = pMxDoc 'QI
pDataGraphs.Add pDataGraph
End Sub
Any help would be appreciated, thanks!
I'm trying to make a chart using VB code, however, I want to specify which fields are used for the X and Y axis.
I've found the following code, which works, but I'm not sure how to go about specifying X and Y axis fields. Any ideas?
Copied and pasted from website.....
Description:
This sample creates a very basic column chart. The code does not specify an X or Y axis field forcing the DataGraph object to automatically select these. For column charts, use IDataGraph::FieldSet1 to specify the y-axis and IDataGraphProperties::XAxisLabelField to specify the x-axis.
This sample provides an simple introduction to creating charts programmatically. There are many different interfaces and members that can be used to create a chart.
How to use:
Paste the code into VBA.
Select a map layer in the table of contents.
From the Macros dialog, run the CreateNewChart routine.
The new data graphy automatically selects two fields to use.
Public Sub CreateNewChart()
Dim pMxDoc As IMxDocument
Dim pDataGraph As IDataGraph
Dim pDataGraphProperties As IDataGraphProperties
Dim pGraphWindow As IDataGraphWindow
Dim pDataGraphs As IDataGraphs
Set pMxDoc = Application.Document
If pMxDoc.SelectedLayer Is Nothing Then Exit Sub
If Not TypeOf pMxDoc.SelectedLayer Is IFeatureLayer Then Exit Sub
'Create a new graph
Set pDataGraph = New DataGraph
'Set the default Table, DataGraph will select a default graph type and some fields
Set pDataGraph.Table = pMxDoc.SelectedLayer
'Specifically give the chart a name and title
pDataGraph.name = pMxDoc.SelectedLayer.name & " Chart"
Set pDataGraphProperties = pDataGraph 'QI
pDataGraphProperties.Title = "My Chart"
pDataGraphProperties.ShowXAxisLabels = True
pDataGraphProperties.ShowLegend = True
pDataGraphProperties.SubTitle = pDataGraph.FieldSet1 & " vs. " & pDataGraphProperties.XAxisLabelField
'Associate the data graph with a data graph window
Set pGraphWindow = New DataGraphWindow
Set pGraphWindow.DataGraph = pDataGraph
Set pGraphWindow.Application = Application
'Add the graph to the system
Set pDataGraphs = pMxDoc 'QI
pDataGraphs.Add pDataGraph
End Sub
Any help would be appreciated, thanks!