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.
This linear regression script works on V 5.7.6. and up.
Example
Regression line to calculate the effect of product price on the company’s revenues.
The most common use of regression line is in scatter charts. Scatter charts have values shown as rounds in different size and color and the regression line helps to understand the connection between both values.
Multiple regression lines in the same line chart
The regression line script allows you to define different regression lines for each value.
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' }; });
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' }; });
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
Updates:
September, 25th 2017 - fixed export to PDF fails when the dimension is disabled and applied with the regression line.
RegressionLine.zip
-
Thanks a lot ! I did not test it yet, but I already have one request : is it possible to extend the time period ? I use regression line as trend line in order to show a probable "landing figure". For instance, in retail, using the revenue for each day of the current month, being able to predict the total revenue by the end of month. At the begining of the month result is very uncertain, but as you approach the 20th or so, you have a pretty good ability to predict what will happen. Same for yearly revenue based on month ...
Thanks for your help.
-
Hi David,
If I understand you correctly, I believe you are seeking a projection analysis.
Please see this forum post on Future trend analysis:
https://support.sisense.com/entries/70165820-Trend-Analysis
Regards,
Inbal
-
I have a line chart that I want to plot 3 values. Two of them are in one table ($$) and one is in another (%). I tried creating a custom SQL statement to UNION ALL the results, however, the one value is a different scale (%) so I want it on the right axis. Can I add a series line to do something like this?
-
Hi all-
You can potentially achieve what you are looking to do with the below two posts.
https://support.sisense.com/hc/en-us/community/posts/221225608-Predictive-Trend-Line-Plugin
https://support.sisense.com/hc/en-us/community/posts/221226348-Trend-Lines-Menu-Based-
Thanks
Ramon
-
In Sisense 7.3 we are running into an issue where we can't send any emails with reports to nobody while we have the Regression plug in on. So we have to turn it off in order to send any report to anybody. Did anybody else run into the same issue? If so, how did you fix the problem? Thanks in advance.
-
Hi Inbal,
I´m doing a bar chart and I included a regression line. The chart with regression is doing well but when I click in other chart to filter the month or a category, the regression is transformed to month results. When I clear the selection the result continue to be month result. So, when I filter I loose the regression. This is not good, I can not use regression in this way. Can you help me please?
Please sign in to leave a comment.
Comments
11 comments