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


How to change label formats and marks on an axis using a line graph (ArcObjects .NET 10.4 SDK)

How to change label formats and marks on an axis using a line graph


Summary
The code in this topic demonstrates how to create a line graph, adjust its axis and marks properties, and change numeric label output formats.

Changing label formats and marks on an axis using a line graph

To use the code in this topic, modify the following parameters:
  • pathToShapeFile—The path to shapefile to build the line graph.
  • seriesFieldName—The numerical field used to build the line graph.
  • pathToOutImage—The 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 change label formats and marks on an axis using a line graph, see the following code:
[C#]
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            IAoInitialize ao=new AoInitializeClass();
            ao.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);
            SampleLineV(@"path to your shapefile", "field name", @
                "path to your output image");
            ao.Shutdown();
        }

        static void SampleLineV(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 a data graph.
            IDataGraphT dataGraphT=new DataGraphTClass();

            // Add a line series.
            ISeriesProperties seriesProps=dataGraphT.AddSeries("line:vertical");
            seriesProps.SourceData=table;
            seriesProps.SetField(1, seriesFieldName);
            seriesProps.Marks=true;
            seriesProps.ValueFormat="0.0E-0"; 
                // This will affect the marks' and legend's numerical output format.

            // Set line thickness.
            seriesProps.PenProperties.Width=2;

            // Set line symbol properties.
            ILineSeriesProperties lineSeriesProps=(ILineSeriesProperties)
                seriesProps;
            lineSeriesProps.SymbolProperties.Style =
                esriDataGraphTSymbolType.esriDataGraphTSymbolCross;
            lineSeriesProps.SymbolProperties.BorderProperties.Color=0x000000ff;

            // Set graph furniture properties.
            dataGraphT.LegendProperties.Visible=false;
            dataGraphT.get_AxisProperties(2).Title=System.IO.Path.GetFileName
                (pathToShapeFile);
            dataGraphT.get_AxisProperties(0).Title=seriesFieldName;
            dataGraphT.get_AxisProperties(0).Logarithmic=true;
            dataGraphT.get_AxisProperties(0).ValueFormat="0.0e-0"; 
                // This will affect the axis label's numerical output format.

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

Shared Sub SampleLineV(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 a data graph.
Dim dataGraphT As IDataGraphT=New DataGraphTClass()

' Add a line series.
Dim seriesProps As ISeriesProperties=dataGraphT.AddSeries("line:vertical")
seriesProps.SourceData=table
seriesProps.SetField(1, seriesFieldName)
seriesProps.Marks=True
seriesProps.ValueFormat="0.0E-0" ' This will affect the marks' and legend's numerical output format.

' Set line thickness.
seriesProps.PenProperties.Width=2

' Set line symbol properties.
Dim lineSeriesProps As ILineSeriesProperties=CType(seriesProps, ILineSeriesProperties)
lineSeriesProps.SymbolProperties.Style=esriDataGraphTSymbolType.esriDataGraphTSymbolCross
lineSeriesProps.SymbolProperties.BorderProperties.Color=110000

' Set graph furniture properties.
dataGraphT.LegendProperties.Visible=False
dataGraphT.AxisProperties(2).Title=System.IO.Path.GetFileName(pathToShapeFile)
dataGraphT.AxisProperties(0).Title=seriesFieldName
dataGraphT.AxisProperties(0).Logarithmic=True
dataGraphT.AxisProperties(0).ValueFormat="0.0e-0" ' This will affect the axis label's numerical output format.

' 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 for Desktop Basic ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced