Skip to content

Trend API

Trend API lists the trend definitions and their tags (each tag = one variable / line on the trend) and lets scripts change a tag’s Y-axis scale at runtime.

Returns every trend definition in the project — Collection<TrendResponseDto>.

var trends = ins.getTrends();
trends.forEach(function(t) {
ins.consoleLog(t.getName() + " period=" + t.getPeriod() + "ms");
});
MethodTypeDescription
getName()StringTrend name
getDsc()StringDescription
getPeriod()IntegerSampling period (ms)
getOrder()IntegerOrder in the UI list
getConfigs()StringSerialized display configuration (JSON string)
getProjectId()StringProject ID

Returns every tag attached to the given trend — Collection<TrendTagResponseDto>.

// Look up the trend id by name
var trends = ins.getTrends();
var target = null;
trends.forEach(function(t) {
if (t.getName() == "Power Trend") target = t;
});
if (target) {
var tags = ins.getTrendTags(target.getBaseId());
tags.forEach(function(tag) {
ins.consoleLog(tag.getVariableName() + " [" + tag.getMinScale() + ", " + tag.getMaxScale() + "]");
});
}
MethodTypeDescription
getName()StringTag name
getDsc()StringDescription
getStatus()BooleanWhether the tag is active
getOrder()IntegerOrder inside the trend
getVariableName() / getVariableUnit()StringBound variable name and unit
getVariableId() / getTrendId()StringReference IDs
getMinScale() / getMaxScale()DoubleY-axis lower/upper bounds
getColor()StringLine color (hex)
getThickness()IntegerLine thickness
getGridThickness()DoubleGrid thickness
getHideValueAxe()BooleanWhether to hide the value axis

ins.setTrendTagMinMaxScale(trendName, tagName, minScale, maxScale)

Section titled “ins.setTrendTagMinMaxScale(trendName, tagName, minScale, maxScale)”

Sets a trend tag’s Y-axis bounds. The trend uses the new range from the next render onward.

ins.setTrendTagMinMaxScale("Power Trend", "ActivePower_kW", 0.0, 500.0);

Dynamically adjust the trend’s Y-axis range based on the last hour of real data, with 10 % margin.

function main() {
var end = ins.now();
var start = ins.getDate(end.getTime() - 3600000);
var stats = ins.getLoggedVariableValueStats(["ActivePower_kW"], start, end);
var s = stats.ActivePower_kW;
if (!s) return;
var margin = (s.getMaxValue() - s.getMinValue()) * 0.1;
ins.setTrendTagMinMaxScale(
"Power Trend", "ActivePower_kW",
s.getMinValue() - margin,
s.getMaxValue() + margin
);
}
main();