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


How to create a 3D pie graph (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > 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 3D pie graph

How to create a 3D pie graph


Summary
This topic shows how to create a three-dimensional (3D) pie graph and adjust the graph's properties.

Creating a 3D pie graph

To create a 3D pie graph using the code in this topic, modify the following parameters:
  1. pathToShapeFile - The shapefile path to create the pie series.
  2. seriesFieldName - The numerical field to use for creating the pie series.
  3. 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.)
[C#]
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            IAoInitialize ao=new AoInitializeClass();
            ao.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);
            SamplePie(@"path to your shapefile", "field name", @
                "path to your output image");
            ao.Shutdown();
        }

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

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

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

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

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

            // Set the pie properties for the first series.
            IPieSeriesProperties pieSeriesProps=(IPieSeriesProperties)seriesProps;
            pieSeriesProps.ExplodeBiggestSlice=50;

            //Set 3D graph mode.
            dataGraphT.GeneralProperties.Show3D=true;

            // 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)
    SamplePie("path to your shapefile", "field name", "path to your output image")
    ao.Shutdown()
End Sub

Shared Sub SamplePie(ByVal pathToShapeFile As String, ByVal seriesFieldName 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 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)

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

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

' Set the pie properties for the first series.
Dim pieSeriesProps As IPieSeriesProperties=CType(seriesProps, IPieSeriesProperties)
pieSeriesProps.ExplodeBiggestSlice=50

'Set 3D graph mode.
dataGraphT.GeneralProperties.Show3D=True

' 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