Click or drag to resize
OSIsoft, LLC

AFSearchHistogramAsyncTBin Method

Generates a histogram using the specified weighting for items matching this search asynchronously.

Namespace:  OSIsoft.AF.Search
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version:
public Task<AFBinnedResult<TBin>> HistogramAsync<TBin>(
	string field,
	IEnumerable<TBin> bins,
	UOM binUOM,
	CancellationToken cancellationToken
where TBin : Object, IComparable<TBin>


Type: SystemString
The field whose value should be binned.
Type: System.Collections.GenericIEnumerableTBin
The bins the field should be sorted into.
Type: OSIsoft.AF.UnitsOfMeasureUOM
The unit of measure associated with bin values.
Type: System.ThreadingCancellationToken
A token to control cancellation of the aggregation request.

Type Parameters

The type of the histogram bins.

Return Value

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

Note Notes to Callers
This call might use a background task to complete some of its work. See the Threading Overview for some matters to consider when execution transitions to another thread.

// 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 = await eventSearch.HistogramAsync("StartTime",
        new AFTimeSpan(months: 1).GetIntervalTimes(new AFTimeRange("1-1y", "1+1mo")), binUOM: null, cancellationToken: CancellationToken.None);
    foreach (var bin in histogram.BinnedResults)
        Console.WriteLine("Month: {0}, Count: {1}",
            bin.Key, bin.Value[AFSummaryTypes.Count]);
Version Information


Supported in: 2.10.5, 2.10, 2.9.5, 2.9
See Also
Enabling Operational Intelligence