Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

AFSearch.Histogram(TBin) Method

  • Last UpdatedJan 12, 2026
  • 3 minute read
AFSearch.Histogram(TBin) Method
Generates a histogram using the specified weighting for items matching this search.

Namespace:  OSIsoft.AF.Search
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.2.0.7

Syntax

public AFBinnedResult<TBin> Histogram<TBin>(
	string field,
	IEnumerable<TBin> bins,
	UOM binUOM
)
where TBin : Object, IComparable<TBin>
Public Function Histogram(Of TBin As {Object, IComparable(Of TBin)}) ( 
	field As String,
	bins As IEnumerable(Of TBin),
	binUOM As UOM
) As AFBinnedResult(Of TBin)

Dim instance As AFSearch
Dim field As String
Dim bins As IEnumerable(Of TBin)
Dim binUOM As UOM
Dim returnValue As AFBinnedResult(Of TBin)

returnValue = instance.Histogram(field, 
	bins, binUOM)
public:
generic<typename TBin>
where TBin : Object, IComparable<TBin>
AFBinnedResult<TBin>^ Histogram(
	String^ field, 
	IEnumerable<TBin>^ bins, 
	UOM^ binUOM
)
member Histogram : 
        field : string * 
        bins : IEnumerable<'TBin> * 
        binUOM : UOM -> AFBinnedResult<'TBin>  when 'TBin : Object and IComparable<'TBin>

Parameters

field
Type: SystemString
The field whose value should be binned.
bins
Type: System.Collections.GenericIEnumerableTBin
The bins the field should be sorted into.
binUOM
Type: OSIsoft.AF.UnitsOfMeasureUOM
The unit of measure associated with bin values.

Type Parameters

TBin
The type of the histogram bins.

Return Value

Type: AFBinnedResultTBin
A result containing the requested histogram or an error if the summaries could not be performed.

Examples

// Get the Database
PISystems myPISystems = new PISystems();
PISystem myPISystem = myPISystems.DefaultPISystem;
if (myPISystem == null)
    throw new InvalidOperationException("Default PISystem was not found.");
AFDatabase myDB = myPISystem.Databases[dbName];
if (myDB == null)
    throw new InvalidOperationException("Database was not found.");

// Create a search to find all the event frames created from the 'Event'
// template in the last year.
using (AFEventFrameSearch eventSearch = new AFEventFrameSearch(myDB, "EventFrameSearch", @"Template:'Event' Start:>'t-1y'"))
{
    eventSearch.CacheTimeout = TimeSpan.FromMinutes(10);
    // Generate a histogram by start month
    AFBinnedResult<AFTime> histogram = eventSearch.Histogram("StartTime",
        new AFTimeSpan(months: 1).GetIntervalTimes(new AFTimeRange("1-1y", "1+1mo")), binUOM: null);
    foreach (var bin in histogram.BinnedResults)
    {
        Console.WriteLine("Month: {0}, Count: {1}",
            bin.Key, bin.Value[AFSummaryTypes.Count]);
    }
}

Version Information

AFSDK

Supported in: 3.1.1, 3.1.0, 3.0.2, 3.0.1, 3.0.0, 2.10.11, 2.10.5, 2.10.0, 2.10, 2.9.5, 2.9

See Also

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in