Click or drag to resize

Changing Trend Properties

The following code snippets can be used/modified to interact with properties of a trend.

C#
// get reference to trend graph control in current screen assuming there is a
// TrendGraph control named "TrendGraph1"
string trendGraphControlName = "TrendGraph1";
ControlTrendGraph trendGraph = Screen.ScreenControls[trendGraphControlName] as ControlTrendGraph;

// get control base using linq. NOTE: we may not know what type of control
// we have since trends can be ControlTrend or ControlTrendCalculation types
ControlBase firstTrend = trendGraph.Children.First() as ControlBase;

// get child trend control by control name
string childTrendControlName = "Trend1";
ControlTrend trend1 = trendGraph.Children[childTrendControlName] as ControlTrend;

// get child trend control by index
int childTrendControlIndex = 2;
ControlTrend trend2 = trendGraph.Children[childTrendControlIndex] as ControlTrend;

// get child trend control using linq
ControlTrend lastTrend = trendGraph.Children.Last() as ControlTrend;

// modify individual trend properties
ControlBase.TrySetProperty(firstTrend, "ScaleMax", 999);
trend1.SourceTag = "<server>view.tag";
trend2.Color = Color.Orange;
lastTrend.IsScaleLeftVisible = false;

// modify property for all child trends assuming all children
// are of the type ControlTrend. Any calculation trends would
// have the type ControlTrendCalculation.
foreach (ControlTrend trend in trendGraph.Children)
{
    trend.LineThickness = 2;
}

// modify property for all child trends that have property
foreach (ControlBase child in trendGraph.Children)
{
    // NOTE: using this method we can set the property
    // value of a control if the control has the specified
    // property without casting to a specific control type.
    string propertyName = "AggregateInterval";
    TimeSpan propertyValue = TimeSpan.FromMinutes(5);
    ControlBase.TrySetProperty(child, propertyName, propertyValue);
}