

Public Class CIMChartBarSeries Inherits CIMChartSeries Implements System.ComponentModel.INotifyPropertyChanged, System.Xml.Serialization.IXmlSerializable
public class CIMChartBarSeries : CIMChartSeries, System.ComponentModel.INotifyPropertyChanged, System.Xml.Serialization.IXmlSerializable
{
// Note: QueuedTask is required to access the feature layer
{
var layerDefinition = featureLayer.GetDefinition();
string fieldXAxis = "textField";
string fieldYAxis = "NumericField";
var myBarChart = new CIMChart
{
Name = "Bar chart",
GeneralProperties = new CIMChartGeneralProperties
{
Title = $"{fieldXAxis} vs. {fieldYAxis}",
UseAutomaticTitle = false
},
Series =
[
new CIMChartBarSeries
{
Name = "Bar chart",
UniqueName = "Bar chart",
Fields = new string[] { fieldXAxis, fieldYAxis },
//Create green fill symbols
FillSymbolProperties = new CIMChartFillSymbolProperties
{
Color = CIMColor.CreateRGBColor(38, 115, 0, 70)
}
}
]
};
// Add new chart to layer's existing list of charts (if any exist)
var newBarCharts = new CIMChart[] { myBarChart };
var allChartsBar = (layerDefinition.Charts == null) ? newBarCharts : layerDefinition.Charts.Concat(newBarCharts);
// Add CIM chart to layer definition
layerDefinition.Charts = allChartsBar.ToArray();
featureLayer.SetDefinition(layerDefinition);
}
}
{
// For more information on the chart CIM specification:
// https://github.com/Esri/cim-spec/blob/main/docs/v3/CIMCharts.md
var lyrDefBar = featureLayer.GetDefinition();
// Get unique values for `splitByField`
var values = new List<string>();
using (RowCursor cursor = featureLayer.Search())
{
while (cursor.MoveNext())
{
var value = Convert.ToString(cursor.Current[splitByField]);
values.Add(value);
}
}
;
var uniqueValues = values.Distinct().ToList();
// Define bar chart CIM properties
var barChart = new CIMChart
{
Name = "barChart",
GeneralProperties = new CIMChartGeneralProperties
{
Title = $"{categoryField} grouped by {splitByField}",
UseAutomaticTitle = false
},
};
// Create list to store the info for each chart series
var allSeries = new List<CIMChartSeries>();
// Create a series for each unique category
foreach (var value in uniqueValues)
{
var series = new CIMChartBarSeries
{
UniqueName = value,
Name = value,
// Specify the category field
Fields = new string[] { categoryField, string.Empty },
// Specify the WhereClause to filter a series by unique value
WhereClause = $"{splitByField} = '{value}'",
GroupFields = new[] { categoryField },
// Specify aggregation type
FieldAggregation = new string[] { string.Empty, "COUNT" }
};
allSeries.Add(series);
}
barChart.Series = allSeries.ToArray();
// Add new chart to layer's existing list of charts (if any exist)
var newChartsBar = new CIMChart[] { barChart };
var allBarCharts = (lyrDefBar == null) ? newChartsBar : lyrDefBar.Charts.Concat(newChartsBar);
// Add CIM chart to layer definition
lyrDefBar.Charts = allBarCharts.ToArray();
featureLayer.SetDefinition(lyrDefBar);
}
System.Object
ArcGIS.Core.CIM.CIMObject
ArcGIS.Core.CIM.CIMChartSeries
ArcGIS.Core.CIM.CIMChartBarSeries
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)