Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making a chart using VB

Status
Not open for further replies.

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!
 
Hi,

What application are you using to code your VBA?

What Object Library did you reference, that has the IDataGraph Object?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks for the info.

Where is the DATA for your x & y ranges?

FYI:
Don't know how much help you'll get here. Most of the VBA in this forum is strictly related to MS applications. This will depend if some of our members have experience with the ArcMapUI Object Model.

Check around for for GIS forums like Forum1593.


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi,

Thanks for the info.

My X and Y data are help in columns in the selected layer. According to the description of the sub-routine: "The code does not specify an X or Y axis field forcing the DataGraph object to automatically select these." - Ideally, I want to tell it which to use.

It does go on to say: "For column charts, use IDataGraph::FieldSet1 to specify the y-axis and IDataGraphProperties::XAxisLabelField to specify the x-axis" - but I'm not really sure what this means.

If anybody can help that would be great, otherwise, thanks for the help so far!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top