Creating a 3D pie graph
To create a 3D pie graph using the code in this topic, modify the following parameters:
- pathToShapeFile—The shapefile path to create the pie series.
- seriesFieldName—The numerical field to use for creating the pie 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.)
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):
ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)ESRI.ArcGIS.Geodatabase ESRI.ArcGIS.DataSourcesFile ESRI.ArcGIS.Catalog ESRI.ArcGIS.Display ESRI.ArcGIS.Carto ESRI.ArcGIS.CartoUI System System.Collections.Generic System.Text
Development licensing | Deployment licensing |
---|---|
ArcGIS for Desktop Basic | ArcGIS for Desktop Basic |
ArcGIS for Desktop Standard | ArcGIS for Desktop Standard |
ArcGIS for Desktop Advanced | ArcGIS for Desktop Advanced |