1

I have a combobox that shows all fields of a shapefile.

I want to get these values programmatically in a label--Count, Minimum, Maximum, Sum, Mean, Standard Deviation--and populate a graph of the selectable fields in the combobox. All that in the same form.


It work Jakub, but sometimes it give an error that close all the ArcGIS opened windows.

I did some changes to the code.
This is my code:

Private Sub CmboFld_Change()
 Dim pMxDoc As esriArcMapUI.IMxDocument, pFLayer As esriCarto.IFeatureLayer, pData As esriGeoDatabase.IDataStatistics
 Dim pCursor As esriGeoDatabase.ICursor, pStatResults As esriSystem.IStatisticsResults
 Set pMxDoc = ThisDocument
 Set pFLayer = pMxDoc.FocusMap.Layer(0)
 Set pCursor = pFLayer.Search(Nothing, False)
 
 Set pData = New esriGeoDatabase.DataStatistics
 pData.Field = CmboFld.Text
 Set pData.Cursor = pCursor
 
 Dim pEnumVar As esriSystem.IEnumVariantSimple, value As Variant
 Set pEnumVar = pData.UniqueValues
 value = pEnumVar.Next
 
 Set pCursor = pFLayer.Search(Nothing, False)
 Set pData.Cursor = pCursor
 Set pStatResults = pData.Statistics
 Txt1.Caption = pStatResults.Maximum
 Txt2.Caption = pStatResults.Minimum
 Txt3.Caption = pStatResults.Sum
 Txt4.Caption = pStatResults.Mean
 Txt5.Caption = pStatResults.StandardDeviation
End Sub

and :

Private Sub UserForm_Initialize()
 '------------- Remplir la combobox------------------------------------
 'clear combobox
 CmboFld.Clear
 Dim i As Integer
 Dim pMxDoc As IMxDocument
 Set pMxDoc = ThisDocument
 Dim pFeatureLayer As IFeatureLayer
 Set pFeatureLayer = pMxDoc.FocusMap.Layer(0) '1st layer
 For i = 0 To pFeatureLayer.FeatureClass.Fields.FieldCount - 1
 CmboFld.AddItem pFeatureLayer.FeatureClass.Fields.Field(i).Name
 Next i
End Sub

It work, now I have a problem, how to populate a graph, I did used this:

Private Sub Graph()
 Dim pMxDoc As IMxDocument
 Set pMxDoc = ThisDocument
 
 ' get the name of the layer containing feature points
 Dim pLayer As ILayer
 Set pLayer = pMxDoc.FocusMap.Layer(0)
 
 ' create graph
 Dim pDataGraphBase As IDataGraphBase
 Dim pDataGraphT As IDataGraphT
 Set pDataGraphBase = New DataGraphT
 Set pDataGraphT = pDataGraphBase
 
 Dim layerName As String
 layerName = pLayer.Name
 
 ' graph and legend titles
 pDataGraphT.GeneralProperties.Title = "Graphe"
 pDataGraphT.LegendProperties.Title = "Legende"
 pDataGraphBase.Name = "Graphe représentant - " & layerName
 
 ' create vertical line series
 Dim pSP As ISeriesProperties
 Set pSP = pDataGraphT.AddSeries("line:vertical")
 pSP.colorType = esriGraphColorMatch
 pSP.WhereClause = "GAGE_NO_ = 2 AND YEAR_ = 99"
 pSP.InLegend = True
 
 pSP.SourceData = pLayer
 pSP.SetField 0, "TSDateTime"
 pSP.SetField 1, "TSValue"
 Dim pSortFlds As IDataSortSeriesProperties
 Set pSortFlds = pSP
 Dim idx As Long
 pSortFlds.AddSortingField "TSDateTime", True, idx
 
 Dim pCancelTracker As ITrackCancel
 Set pCancelTracker = New CancelTracker
 pDataGraphT.Update pCancelTracker
 
 ' create data graph window within ArcMap
 Dim pDGWin As IDataGraphWindow2
 Set pDGWin = New DataGraphWindow
 Set pDGWin.DataGraphBase = pDataGraphBase
 Set pDGWin.Application = ThisDocument.Parent
 pDGWin.Show (True)
 
 Dim pDataGraphs As IDataGraphCollection
 Set pDataGraphs = pMxDoc
 pDataGraphs.AddDataGraph pDataGraphBase
 
 ' export the graph instead of displaying in ArcMap, use the following code,
 ' and comment the above 9 lines
 Dim fileName As String
 fileName = Form1.Dir & layerName & ".jpg"
 pDataGraphT.ExportToFile fileName
End Sub
Private Sub CmdGrph_Click()
 Graph
End Sub

It give me an empty graph, with a text zone "There is no selection" when I double click at that zone text, it give me, graph properties I choose this information:

Graph Type: Vertical Bar

Layer/Table: pMxDoc.FocusMap.Layer(0)

Value Field: CmboFld.Text

then it populate the graph.

I want to populate that Graph AUTOMATICALLY when I click at Graph Button.

GforGIS
3,3954 gold badges23 silver badges40 bronze badges
asked Jun 14, 2011 at 10:43
1
  • How will you get these values in a label...can you please explain? Do you want separate labels for each? What about the axis information about the graph...? Commented Jun 14, 2011 at 10:50

1 Answer 1

1

iDataStatistics

Example here: http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeoDatabase/IDataStatistics_Example.htm

answered Jun 14, 2011 at 18:25
4
  • 1
    What exactly doesn't work? Can you be more specific? IDataStatistics:Statistics (IStatisticsResults) will provide you with the required field statistics. Commented Jun 19, 2011 at 21:56
  • it work, i re try it it works know, but sometimes it give an error and close all arcgis opened files.. Commented Jun 20, 2011 at 15:17
  • i did some changes, that's the code i wrote : Commented Jun 20, 2011 at 15:17
  • here is the message error : Erreur d'exécution '-2147417848(80010108)' Erreur Automation L'objet invoqué s'est déconnecté de ses clients Commented Jun 20, 2011 at 15:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.