Adding A Regression Line To Chart
Introduction
Regression line helps us to predict values of one variable, when given values of another variable.
Linear regression assists in predicting trends and improving data analysis.
Steps
A regression line can be added to all widgets with both y and x axis.
We can add a simple linear regression calculation to any line / column / scatter chart by use of a simple js code.
The x and y values must be numeric (int).
In order to add a Regression Line to your widget, please follow the listed steps below:
Step 1:
DOWNLOAD AND EXTRACT THE ENCLOSED FOLDER INTO THE PLUGINS FOLDER:
C:\Program Files\Sisense\PrismWeb\plugins\RegressionLine, if the "plugins" folder is not there, please create it. If you are using version 7.2 and higher unzip the contents into your C:\Program Files\Sisense\app\plugins\ folder.
Step 2:
Create a widget that has both numeric X and Y axis (bar chart, line chart, scatter chart etc.).
Step 3:
Open the widget editor, edit script. Copy the js code below into the script editor.
widget.on('processresult', function(sender, args) {
args.result.series[0].regression = true;
args.result.series[0].regressionSettings = {
type: 'linear',
color: '#29a2a4',
dashStyle : 'dash',
name : 'regression line'
};
});
args.result.series[0].regression = true;
args.result.series[0].regressionSettings = {
type: 'linear',
color: '#29a2a4',
dashStyle : 'dash',
name : 'regression line'
};
});
If you want multiple regression lines just add the same definition for the next regression line For example:
widget.on('processresult', function(sender, args) {
args.result.series[0].regression = true;
args.result.series[0].regressionSettings = {
type: 'linear',
color: '#29a2a4',
dashStyle : 'dash',
name : 'regression line'
};
args.result.series[1].regression = true;
args.result.series[1].regressionSettings = {
type: 'linear',
color: '#29a2a4',
dashStyle : 'dash',
name : 'regression line2'
};
});
args.result.series[0].regression = true;
args.result.series[0].regressionSettings = {
type: 'linear',
color: '#29a2a4',
dashStyle : 'dash',
name : 'regression line'
};
args.result.series[1].regression = true;
args.result.series[1].regressionSettings = {
type: 'linear',
color: '#29a2a4',
dashStyle : 'dash',
name : 'regression line2'
};
});
Code configuration:
Make sure you change the name 'regression line' to a meaningful name.
You can edit the script and choose different color or
regression types (see explanation in the readme file in the attached Zip file)
Press SAVE
Close the Script window
Step 4:
Refresh the Widget and click apply
The chart should appear with the regression line
Updated 03-02-2023
intapiuser
Admin
Joined December 15, 2022