Skip to main content

Graphs and charts or another source

Line graphs display historical data from the iRidi Server database or another source. Charts visually compare several values in a visualization interface

Line graphs (Linear Trend)​

Linear Trend is a graph of a variable's changes, with points representing its values connected by lines. A graph can display changes in several variables over time.

The graph displays values from the iRidi Server database, an external database, or an array created with JavaScript. Several Linear Trend parameters can be changed from scripts.

i3 pro does not maintain its own database, so graphs usually display information received from iRidi Server.

Configuring graphs

  1. Save the feedback change history to the iRidi Server database
  2. Configure history display on the graph: create a Linear Trend graphic item in the i3 pro interface and bind it to the server feedback whose history you are displaying

1. Save feedback history to the iRidi Server database​

Driver Feedback or virtual Feedback can be recorded in the database. Database storage settings are available in the iRidi Server logic project: configuring iRidi Server feedbacks

2. Display a variable's history on the graph​

Create a Linear Trend graphic item in the i3 pro interface and bind it to the server feedback whose history you are displaying:

Studio2019_Server_Trend_Feedbacks.png

Double-click the item to open appearance and range settings for the graph and each of its curves:

Studio2019_Server_Trend_Settings.png

General settings for the graph (General):

  • Horizontal axis (time)
    • Range - the range along the time axis
    • Position - time-axis position: above or below the graph
    • Make marks by - marks at the specified interval in seconds/minutes/hours/days
    • Divisions between marks - number of subdivisions between marks
  • Vertical axis (data)
    • Auto-scaling - automatically scales from zero to the received value, or
    • Min ... Max (when Auto-scaling is off) - fixed data-display range
    • Position - data-axis position: left or right of the graph
    • Make marks by - marks at the specified integer interval
    • Divisions between marks - additional divisions between major marks
  • List of curves displayed on the graph, and their settings
    • Name - curve name, which can be displayed on the axis
    • Tag - server variable supplying data for the curve
    • Main curve (for auto-scaling) - mark the curve as the main curve for automatic scaling
    • Line type - curve type
      • Line - curve points connected by straight segments forming a continuous line
      • Dotted line - curve points connected by straight segments forming a dotted line
      • Square line - steps from point to point forming a continuous line
    • Width - line or point thickness
    • Color - line color

Chart area settings (Appearance):

  • Chart and axis area fills
  • Horizontal axis (time): line, marks, additional marks, mark text, and axis heading
  • Vertical axis (data): line, marks, additional marks, mark text, and axis heading
  • Cursor in the chart area

Chart area settings"

Studio2019_Server_Trend_Settings_1.png

Chart area. Chart and axis area fills

  • Axis area - axis area fill and border
    • Fill - fill
      • Color - fill color
      • Opacity - overall opacity of the axis area
    • Border - border around the axes
        • Color - border color
      • Width - border width
  • Chart area - chart area fill
    • Fill - fill
      • Color - fill color
      • Opacity - overall opacity of the chart area

Studio2019_Server_Trend_Settings_2.png

Horizontal axis (time). Horizontal axis (time): line, marks, additional marks, mark text, and heading

  • Axis line and time scale - axis line and major marks
    • Axis and scale color - color of the axis line and marks
    • Scale mark size - mark height
  • Time on scale marks - time labels on marks
    • Show - display time labels on marks
    • Template - time display format on marks
    • Font - font settings and text color on marks
    • Indent from axis - text offset from the axis line, depending on mark height and font size
  • Additional marks between scale marks - additional marks
    • Scale mark color - additional-mark color
    • Scale mark size - additional-mark height
  • Axis heading - axis heading
    • Show - display the heading
    • Heading - heading text
    • Font - font settings and heading text color

Studio2019_Server_Trend_Settings_3.png

Vertical axis (data). Vertical axis (data): line, marks, additional marks, mark text, and heading

  • Axis line and time scale - axis line and major marks
    • Axis and scale color - color of the axis line and marks
    • Scale mark size - mark height
  • Time on scale marks - values on marks
    • Show - display values on marks
    • Template - value display format on marks
    • Font - font settings and text color on marks
    • Indent from axis - text offset from the axis line, depending on mark height and font size
  • Additional marks between scale marks - additional marks
    • Scale mark color - additional-mark color
    • Scale mark size - additional-mark height
  • Axis heading - axis heading
    • Show - display the heading
    • Heading - heading text
    • Font - font settings and heading text color

Studio2019_Server_Trend_Settings_4.png

Cursor in chart area. Cursor in the chart area (Windows)

  • Show - display the cursor
  • Color - cursor color
  • Hide in (ms) - hide after the specified idle time

Trend1.png Trend2.png Trend3.png

Populating a graph with a JavaScript data array​

Pass data to a graph curve as a two-dimensional array containing the coordinates of its points.

Example array: var l_aArray = [[0, 60], [1, 30], [2, 90], [3, 10], [4, 60], [5, 20], [6, 80]];

Example implementation:

function trend_processer(trend, curve_name) {
var trend_curve = trend.GetCurve(curve_name);
trend_curve.SetCurveTag("");
trend.EndTime = new iDate();

this.Show = function (data_array) {
trend_curve.SetData(data_array, 0, data_array.length - 1);
}
}

// get a curve
var Curve1 = new trend_processer(IR.GetPage("Page 1").GetItem("Item 1"),
"Main curve");

// display data
Curve1.Show([[0, 60], [1, 30], [2, 90], [3, 10], [4, 60], [5, 20], [6, 80]]);

Resulting curve:

Studio2019_Trend_from_array.png Studio2019_Trend_from_array_curve.png

Populating a graph from an external SQL database​

To display information from an external database:

  1. Configure the ODBC driver in the iRidi Server project and add script #1
  2. Create a virtual tag to transfer data from the server project to the Panel Project
  3. Create an i3 pro interface, and add a Linear Trend item to display the data and script #2

Script #1 for iRidi Server:

IR.AddListener(IR.EVENT_START,0,function()
{
IR.SetTimeout(2000, function(){
var MySQL = new ODBC("root", "", "MySQLresurs"); // creating database connection object
if(MySQL == false)
{
IR.Log("Wrong connection");
}
else
{
IR.Log("Right connection");
}
var response = MySQL.Query("SELECT * FROM test");
if (response) // if connection is successful and answer exists
{
var rows = response.GetRows();
var columns = response.GetColumns();
var data = {}; // two-dimension array with query result
for (var i = 0; i < columns; i++) {
var colName = response.GetColumnName(i);
data[colName] = [];
for (var j = 0; j < rows; j++) {
data[colName][j] = response.GetRowValue(i, j);
}
}
response.Free(); // free memory of recordset (optional action for memory optimization)
IR.Log(JSON.Stringify(data));
IR.SetVariable("Server.Tags.Data",JSON.Stringify(data));
}
});
});

Script #2 for i3 pro:

var l_oDevice = IR.GetDevice("iRidi Server");
var l_oPage = IR.GetPage("Page 1");
var l_oTrend = l_oPage.GetItem("Item 1");
var L_oCurve = l_oTrend.GetCurve("test");
var l_aArray = [];

IR.AddListener(IR.EVENT_TAG_CHANGE, l_oDevice ,function(m_sTag, m_sData) {
if(m_sTag == "Data"){
l_aArray = [];
var m_oData = JSON.Parse(m_sData);
for(var Index in m_oData["X"]){
l_aArray[Index] = [m_oData["X"][Index], m_oData["Y"][Index]+0];
}
}
});

Configuring a graph with JavaScript​

Like other items, Linear Trend has parameters accessible directly from scripts. The following script logs the graph's start time (StartTime):

var trend = IR.GetPage("Page 1").GetItem("Item 1"); // Получаем указатель на график.
IR.Log("Trend start:"+trend.StartTime); // Выводим время начала работы тренда в виде десятичного числа.
var date = new iDate(trend.StartTime); // Осуществляем перевод числа в формат даты.
IR.Log("Year = " + date.year);
IR.Log("Month = " + date.month);
IR.Log("Date = " + date.date);
IR.Log("Hours = " + date.hours);
IR.Log("Minutes = " + date.minutes);
IR.Log("Seconds = " + date.seconds);

This script logs the graph's range (Range):

date = new iDate(trend.Range);
IR.Log("RANGE = "+date.minutes);

To change the range, and therefore the X-axis scale, change Range: trend.Range = 0.00138889; //Для Range число 1 = 1 дню, значит 1 час = 1/24 и т.д.

To change the Y-axis settings, you need to know the name of the required curve:

  1. Open the trend settings,
  2. Open General,
  3. Select the required curve.

Trend5.png

var graph= trend.GetCurve("Feedback 1"); //Получаем указатель на нужный график
//Выводим в лог информацию о графике:
IR.Log("Curve min:" + graph.Min); // Минимальное значение шкалы OY
IR.Log("Curve max:" +graph.Max); // Максимальное значение шкалы OY
IR.Log("Curve color:" +graph.Color); // Цвет графика

Change these parameters:

graph.Min = 0;
graph.Max = 75;
graph.Color = 0x00FF00FF; //Обратите внимание на шаблон изменения цвета: 0x - перевод из системы счисления HEX в DEС, первые 6 символов - цветовая палитра RGB, последние два - прозрачность (FF - непрозрачный, 00 - полностью прозрачный)

Use trend scrolling to view the history of feedback parameter changes. This lets you track changes without switching the trend mode.

function left() {
trend.Stop; // Происходит остановка тренда
trend.StartTime = trend.StartTime-1/720; // перемещение относительно шкалы ОХ на определённое время назад
trend.EndTime = trend.EndTime-1/720; // 1/720 - смещение времени на две минуты
};

function right() {
trend.Stop; // Происходит остановка тренда
trend.StartTime = trend.StartTime+1/720; // Смещение шкалы ОХ на определённое время вперёд
trend.EndTime = trend.EndTime+1/720;
};

More information on graph properties and methods is available here.

Pie and bar charts​

Charts visually compare several values in a visualization interface. They use current variable values rather than historical data, so they also work without iRidi Server.

Pie chart (Pie Chart)​

Pie Chart is divided into slices to illustrate numerical proportions. Each slice's arc length is proportional to the value it represents.

PieChart2.png

TypePie Chart
SectorGapGap between slices.
ConvasColorBackground color of the item containing the chart.
ConvasOpacityItem background opacity from 0 to 255.
BorderColorBorder around the item's background.
BorderDepthWidth of the item's background border.
ChartSectorsAdd and configure pie-chart slices. Configure the chart using scripts or parameter settings in iRidi Studio.

Configuring a chart in iRidi Studio​

PieChart1.png

  1. Open pie-chart settings by double-clicking the item or using its ChartSectors parameter on the dynamic toolbar.
  2. Click "+" to add a pie-chart slice.
  3. Set each slice's parameters:
  • Name - slice name,
  • Token - token whose value is displayed on the pie chart,
  • Color - slice color.

Example:

Configuring a chart with scripts​

The chart receives an array of objects representing slices, with Value (an integer) and Color (a HEX color code) keys. Control the value and color while the client runs by passing new values to array objects. Add or remove array items to change the number of slices.

Example #1 of populating a chart:

var chart = IR.GetItem("PiePage").GetItem("pie");

chart.Data = [
{
Value: 20,
Color: 0xF7464AFF,
},
{
Value: 45,
Color: 0x46BFBDFF,
},
{
Value: 100,
Color: 0xFDB45CFF,
}
];

Example #2 of populating a chart from different data sources:

// add a new Pie
var Pie_1 = new pie_processer(IR.GetItem("PiePage").GetItem("pie"));

// add a constant as piece of Pie
Pie_1.AddPiece("Orange", 0xFDB45CFF, 30);

// remove one of piecs
Pie_1.RemovePiece("Orange");

// change a pice on the level release
IR.AddListener(IR.EVENT_ITEM_RELEASE, IR.GetItem("PiePage").GetItem("level_1"), function() {
var value = IR.GetItem("PiePage").GetItem("level_1").Value;
Pie_1.AddPiece("Red", 0xF7464AFF, value);
});

// one more piece that displayed on "tag change" of Driver
IR.AddListener(IR.EVENT_TAG_CHANGE, IR.GetDevice("KNX"), function(name,value) {
if (name = "1/1/1") {
Pie_1.AddPiece("Green", 0x2EFF0AFF, value);
}
});


// processing of added PieCharts
function pie_processer(chart) {
var piece = {};

this.AddPiece = function (in_name, in_color, in_value) {
piece[in_name] = {Color: in_color, Value: in_value};
update_pie();
};

this.RemovePiece = function (in_name) {
delete piece[in_name];
update_pie();
};

function update_pie() {
var data = [];
for (key in piece) {
data.push(piece[key]);
}
chart.Data = data;
};
}

Bar chart (Bar Chart)​

Bar Chart compares several values represented by rectangles whose heights or lengths are proportional to the values they represent. The chart is populated from scripts.

The chart is populated from scripts. It receives an array of objects representing chart slices with Value (an integer) and Color (a HEX color code) keys. Control the value and color while the client runs by passing new values to array objects. Add or remove array items to change the number of slices.

Example #1 of populating a chart:

IR.AddListener(IR.EVENT_START, 0, function () {

var chart1 = IR.GetItem("BarPage").GetItem("bar1");

chart1.Data = {
Labels : ["Value"], // text on the horizontal axis
Datasets : [{
FillColor : 0x0099CC80, // column color
StrokeColor : 0xFF0004FF, // column border color
Data : [100] // var value
}, {
FillColor : 0x9933CC80,
StrokeColor : 0x00FF33FF,
Data : [100]
}, {
FillColor : 0xFF33CC80,
StrokeColor : 0xFF33CCFF,
Data : [100]
}]
}

chart1.ChartType = 1; // column / stack / square
chart1.StrokeWidth = 3; // the width of a single column
chart1.BarGap = 1; // the distance between columns
chart1.SetGap = 8;
chart1.GridColor = 0xFF0000FF; // the color of greed
chart1.GridStep = 25; // the distance between greed lines
chart1.ShiftX = 10; // the diatance betweeenhorizontal axis and columns
chart1.TextColor = 0xFF0000FF; // the color of labels and greed numbers
});