This document is archived and information here might be outdated.  Recommended version.


How to create a function series graph (ArcObjects .NET 10.5 SDK)

How to create a function series graph


Summary
This topic shows how to create a function graph and make changes to function-specific parameters.

Creating a function series graph

To create a function series graph, modify the following parameters:
  • pathToShapeFile—The path to shapefile to build the function graph.
  • seriesFieldName—The numerical field used to build the bar series as the data source for function series.
  • pathToOutImage—The output file containing an image of the graph (see the application programming interface [API] documentation for the appropriate format extension in IDataGraphBase.ExportToFile).
See the following code example:
[C#]
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            IAoInitialize ao=new AoInitializeClass();
            ao.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);
            SampleFunctionSmoothing(@"path to your shapefile", "field name", @
                "path to your output image");
            ao.Shutdown();
        }

        static void SampleFunctionSmoothing(String pathToShapeFile, String
            seriesFieldName, String pathToOutImage)
        {

            // Open workspace for input shapefile.
            IWorkspaceFactory shapefileWorkspaceFactory=new
                ShapefileWorkspaceFactoryClass();
            IWorkspace shapefileWorkspace;
            shapefileWorkspace=shapefileWorkspaceFactory.OpenFromFile
                (System.IO.Path.GetDirectoryName(pathToShapeFile), 0);
            IFeatureWorkspace featureWorkspace=(IFeatureWorkspace)
                shapefileWorkspace;

            // Get table for input shapefile.
            ITable table=(ITable)featureWorkspace.OpenFeatureClass
                (System.IO.Path.GetFileNameWithoutExtension(pathToShapeFile));

            // Create data graph.
            IDataGraphT dataGraphT=new DataGraphTClass();

            // Add bar series.
            ISeriesProperties seriesProps=dataGraphT.AddSeries("bar:vertical");
            seriesProps.SourceData=table;
            seriesProps.SetField(1, seriesFieldName);

            // Add function series.
            ISeriesProperties funcSeriesProps=dataGraphT.AddSeries("ftSmoothing");

            // The only valid data source for the function series is another nonfunction series unique name.
            funcSeriesProps.SourceData=seriesProps.UniqueName;
            funcSeriesProps.CustomColor=0x000000ff;

            // Set smoothing function-specific parameters.
            IFunctionSeriesProperties funcProps=(IFunctionSeriesProperties)
                funcSeriesProps;
            funcProps.set_Property("FACTOR", 4);
            funcProps.set_Property("LINE_PASSES_POINTS", true);

            // Update data graph.
            dataGraphT.Update(null);

            // Export graph to file (format depends on file extension).
            dataGraphT.ExportToFile(pathToOutImage);
        }
    }
}
[VB.NET]
Namespace ConsoleApplication1VBNET

Class Program
    Shared Sub Main(ByVal args() As String)
    Dim ao As IAoInitialize=New AoInitializeClass()
    ao.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic)
    SampleFunctionSmoothing("path to your shapefile", "field name", "path to your output image")
    ao.Shutdown()
End Sub

Shared Sub SampleFunctionSmoothing(ByVal pathToShapeFile As String, ByVal seriesFieldName As String, ByVal pathToOutImage As String)

' Open workspace for input shapefile.
Dim shapefileWorkspaceFactory As IWorkspaceFactory=New ShapefileWorkspaceFactoryClass()
Dim shapefileWorkspace As IWorkspace
shapefileWorkspace=shapefileWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(pathToShapeFile), 0)
Dim featureWorkspace As IFeatureWorkspace=CType(shapefileWorkspace, IFeatureWorkspace)

' Get table for input shapefile.
Dim table As ITable=CType(featureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(pathToShapeFile)), ITable)

' Create data graph.
Dim dataGraphT As IDataGraphT=New DataGraphTClass()

' Add bar series.
Dim seriesProps As ISeriesProperties=dataGraphT.AddSeries("bar:vertical")
seriesProps.SourceData=table
seriesProps.SetField(1, seriesFieldName)

' Add function series.
Dim funcSeriesProps As ISeriesProperties=dataGraphT.AddSeries("ftSmoothing")

' The only valid data source for the function series is another nonfunction series unique name.
funcSeriesProps.SourceData=seriesProps.UniqueName
funcSeriesProps.CustomColor=110000

' Set smoothing function-specific parameters.
Dim funcProps As IFunctionSeriesProperties=CType(funcSeriesProps, IFunctionSeriesProperties)
funcProps.Property("FACTOR")=4
funcProps.Property("LINE_PASSES_POINTS")=True

' Update data graph.
dataGraphT.Update(Nothing)

' Export graph to file (format depends on file extension).
dataGraphT.ExportToFile(pathToOutImage)
End Sub

End Class

End Namespace






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced