Grouping data into separate lines on a line graph
To use the code in this topic, modify the following parameters:
- pathToFeatureLayer—Path to the feature layer. The feature layer is also used as the source for assigning color for groups.
- seriesXValueFieldName—Field used for the x-coordinate line graph to sort line groups.
- seriesYValueFieldName—Field used as the value field for the line graph.
- seriesGroupFieldName—Field used in grouping data into separate lines.
- 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.
Use the StreamFlowDateTime data as follows:
- <your ArcGIS developer kit install location>\Samples\data\StreamflowDateTime\timsertool.lyr as the pathToFeatureLayer.
- TSDateTime as the seriesXValueFieldName.
- TSValue as the seriesYValueFieldName.
- GAGE_NO_ as the seriesGroupFieldName.
To group data into separate lines on 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);
SampleGrouping(@"path to your feature layer file", "X field name",
"Y field name", "group field name", @"path to your output image");
ao.Shutdown();
}
static void SampleGrouping(String pathToFeatureLayer, String
seriesXValueFieldName, String seriesYValueFieldName, String
seriesGroupFieldName, String pathToOutImage)
{
// Open a feature layer from disk.
IGxLayer gxLayer = new GxLayerClass();
IGxFile gxFile = (IGxFile)gxLayer;
gxFile.Path = pathToFeatureLayer;
// Get the table for the input feature layer.
ITable table = (ITable)gxLayer.Layer;
// Create the data graph.
IDataGraphT dataGraphT = new DataGraphTClass();
dataGraphT.get_AxisProperties(0).Logarithmic = true;
dataGraphT.LegendProperties.Visible = false;
// Add the first line series.
ISeriesProperties seriesProps = dataGraphT.AddSeries("line:vertical");
seriesProps.SourceData = table;
seriesProps.SetField(0, seriesXValueFieldName);
seriesProps.SetField(1, seriesYValueFieldName);
// Group the line series by seriesGroupFieldName.
int index = - 1;
IDataGroupSeriesProperties groupProps = (IDataGroupSeriesProperties)
seriesProps;
groupProps.AddGroupField(seriesGroupFieldName, ref index);
// Sort groups of line series by seriesXValueFieldName.
IDataSortSeriesProperties sortProps = (IDataSortSeriesProperties)
seriesProps;
sortProps.AddSortingField(seriesXValueFieldName, true, ref index);
// Note: This is data-dependent code. Remove or modify the next line
// if you use data other than the sample data referenced in this topic.
dataGraphT.get_AxisProperties(2).DateTimeFormat = "d/m/yy";
// 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)
SampleGrouping("path to your feature layer file", "X field name", "Y field name", "group field name", "path to your output image")
ao.Shutdown()
End Sub
Shared Sub SampleGrouping(ByVal pathToFeatureLayer As String, ByVal seriesXValueFieldName As String, ByVal seriesYValueFieldName As String, ByVal seriesGroupFieldName As String, ByVal pathToOutImage As String)
' Open a feature layer from disk.
Dim gxLayer As IGxLayer = New GxLayerClass()
Dim gxFile As IGxFile = CType(gxLayer, IGxFile)
gxFile.Path = pathToFeatureLayer
' Get the table for the input feature layer.
Dim table As ITable = CType(gxLayer.Layer, ITable)
' Create the data graph.
Dim dataGraphT As IDataGraphT = New DataGraphTClass()
dataGraphT.AxisProperties(0).Logarithmic = True
dataGraphT.LegendProperties.Visible = False
' Add the first line series.
Dim seriesProps As ISeriesProperties = dataGraphT.AddSeries("line:vertical")
seriesProps.SourceData = table
seriesProps.SetField(0, seriesXValueFieldName)
seriesProps.SetField(1, seriesYValueFieldName)
' Group the line series by seriesGroupFieldName.
Dim index As Integer = -1
Dim groupProps As IDataGroupSeriesProperties = CType(seriesProps, IDataGroupSeriesProperties)
groupProps.AddGroupField(seriesGroupFieldName, index)
' Sort groups of line series by seriesXValueFieldName.
Dim sortProps As IDataSortSeriesProperties = CType(seriesProps, IDataSortSeriesProperties)
sortProps.AddSortingField(seriesXValueFieldName, True, index)
' Note: This is data-dependent code. Remove or modify the next line
' if you use data other than the sample data referenced in this topic.
dataGraphT.AxisProperties(2).DateTimeFormat = "d/m/yy"
' 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.SystemUI 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 |