How to create a box plot graph (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Interacting with and configuring maps, layers, and graphics > Working with graphs > How to create a box plot graph (ArcObjects .NET 10.6 SDK)

How to create a box plot graph


Summary
The code in this topic demonstrates how to create a box plot graph.

Creating a box plot graph

To use the code in this topic, modify the following parameters:
  • pathToShapeFile—Path to shapefile to create a box plot series.
  • seriesFieldName—Numerical field to create a box plot series.
  • pathToShapeFile2—Path to shapefile to create a second box plot series.
  • seriesFieldName2—Numerical field to create a second box plot series.
  • pathToOutImage—Output file containing an image of the graph. Refer to the application programming interface (API) documentation for the appropriate format extension in IDataGraphBase.ExportToFile.
To create a box plot graph, see the following code:
[C#]
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            IAoInitialize ao=new AoInitializeClass();
            ao.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);
            SampleBoxplot(@"path to your shapefile", "field name", @
                "path to your shapefile", "field name", @"path to your output image")
                ;
            ao.Shutdown();
        }

        static void SampleBoxplot(String pathToShapeFile, String seriesFieldName,
            String pathToShapeFile2, String seriesFieldName2, String pathToOutImage)
        {

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

            // Get the table for the input shapefile.
            ITable table=(ITable)featureWorkspace.OpenFeatureClass
                (System.IO.Path.GetFileNameWithoutExtension(pathToShapeFile));
            featureWorkspace=(IFeatureWorkspace)shapefileWorkspace2;
            ITable table2=(ITable)featureWorkspace.OpenFeatureClass
                (System.IO.Path.GetFileNameWithoutExtension(pathToShapeFile2));

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

            // Add the first box plot series.
            ISeriesProperties seriesProps=dataGraphT.AddSeries("box_plot");
            seriesProps.SourceData=table;
            seriesProps.SetField(0, seriesFieldName);

            // Set box plot properties for the first series.
            IBoxPlotSeriesProperties boxSeriesProps=(IBoxPlotSeriesProperties)
                seriesProps;
            boxSeriesProps.WhiskerLength=1.0;

            // Add the second box plot series.
            seriesProps=dataGraphT.AddSeries("box_plot");
            seriesProps.SourceData=table2;
            seriesProps.SetField(0, seriesFieldName2);

            // Set box plot properties for the second series.
            boxSeriesProps=(IBoxPlotSeriesProperties)seriesProps;
            boxSeriesProps.WhiskerLength=1.0;

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

            // Export the graph to file (the format depends on the 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)
    SampleBoxplot("path to your shapefile", "field name", "path to your shapefile", "field name", "path to your output image")
    ao.Shutdown()
End Sub

Shared Sub SampleBoxplot(ByVal pathToShapeFile As String, ByVal seriesFieldName As String, ByVal pathToShapeFile2 As String, ByVal seriesFieldName2 As String, ByVal pathToOutImage As String)

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

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

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

' Add the first box plot series.
Dim seriesProps As ISeriesProperties=dataGraphT.AddSeries("box_plot")
seriesProps.SourceData=table
seriesProps.SetField(0, seriesFieldName)

' Set box plot properties for the first series.
Dim boxSeriesProps As IBoxPlotSeriesProperties=CType(seriesProps, IBoxPlotSeriesProperties)
boxSeriesProps.WhiskerLength=1.0

' Add the second box plot series.
seriesProps=dataGraphT.AddSeries("box_plot")
seriesProps.SourceData=table2
seriesProps.SetField(0, seriesFieldName2)

' Set box plot properties for the second series.
boxSeriesProps=CType(seriesProps, IBoxPlotSeriesProperties)
boxSeriesProps.WhiskerLength=1.0

' Update the data graph.
dataGraphT.Update(Nothing)

' Export the graph to file (the format depends on the 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