Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My solution is to add an extra datapoint at the beginning and end of each trendline based on the minimum and maximum x values in the scatterplot.</p> <p>This can be done by </p> <ul> <li>calculating the slope of the trendline</li> <li>calculating the intercept of the trendline</li> <li>getting the minimum x value in the scatterplot</li> <li>getting the maximum x value in the scatterplot</li> <li>calculating the minimum y value by using the slope, intercept and minimum x value</li> <li>calculating the maximum y value by using the slope, intercept and maximum x value</li> <li>adding two points with the x and y values to the trendline</li> </ul> <p>The following code snippet adds start and end points to two trendlines followed by simple functions to calculate slope and intercept:</p> <pre><code> if (Chart1.Series["Budget Year"].Points.Count &gt; 2 &amp;&amp; Chart1.Series["Actual Last Year"].Points.Count &gt; 2) { Chart1.DataManipulator.FinancialFormula(FinancialFormula.Forecasting, "Linear,0,false,false", Chart1.Series["Budget Year"], Chart1.Series["Trendline (Budget Year)"]); Chart1.DataManipulator.FinancialFormula(FinancialFormula.Forecasting, "Linear,0,false,false", Chart1.Series["Actual Last Year"], Chart1.Series["Trendline (Actual Last Year)"]); double budgetSlope = Utility.GetSlope(Chart1.Series["Trendline (Budget Year)"].Points[0], Chart1.Series["Trendline (Budget Year)"].Points[1]); double lastYearSlope = Utility.GetSlope(Chart1.Series["Trendline (Actual Last Year)"].Points[0], Chart1.Series["Trendline (Actual Last Year)"].Points[1]); double budgetIntercept = Utility.GetIntercept(Chart1.Series["Trendline (Budget Year)"].Points[0], Chart1.Series["Trendline (Budget Year)"].Points[1]); double lastYearIntercept = Utility.GetIntercept(Chart1.Series["Trendline (Actual Last Year)"].Points[0], Chart1.Series["Trendline (Actual Last Year)"].Points[1]); double minBudgetRevenue = Convert.ToDouble(dt.Select("RevCurrBudget = MIN(RevCurrBudget)")[0]["RevCurrBudget"]); double maxBudgetRevenue = Convert.ToDouble(dt.Select("RevCurrBudget = MAX(RevCurrBudget)")[0]["RevCurrBudget"]); double minLastYearRevenue = Convert.ToDouble(dt.Select("RevPrevActual = MIN(RevPrevActual)")[0]["RevPrevActual"]); double maxLastYearRevenue = Convert.ToDouble(dt.Select("RevPrevActual = MAX(RevPrevActual)")[0]["RevPrevActual"]); double minBudgetEBIT = (budgetSlope * minBudgetRevenue) + budgetIntercept; double maxBudgetEBIT = (budgetSlope * maxBudgetRevenue) + budgetIntercept; double minLastYearEBIT = (lastYearSlope * minLastYearRevenue) + lastYearIntercept; double maxLastYearEBIT = (lastYearSlope * maxLastYearRevenue) + lastYearIntercept; Chart1.Series["Trendline (Budget Year)"].Points.InsertXY(0, minBudgetRevenue, minBudgetEBIT); Chart1.Series["Trendline (Budget Year)"].Points.AddXY(maxBudgetRevenue, maxBudgetEBIT); Chart1.Series["Trendline (Actual Last Year)"].Points.InsertXY(0, minLastYearRevenue, minLastYearEBIT); Chart1.Series["Trendline (Actual Last Year)"].Points.AddXY(maxLastYearRevenue, maxLastYearEBIT); } public static double GetSlope(DataPoint pt1, DataPoint pt2) { return GetSlope(pt1.XValue, pt1.YValues[0], pt2.XValue, pt2.YValues[0]); } public static double GetSlope(double x1, double y1, double x2, double y2) { return (y2 - y1) / (x2 - x1); } public static double GetIntercept(DataPoint pt1, DataPoint pt2) { double slope = GetSlope(pt1, pt2); double y = pt1.YValues[0]; double x = pt1.XValue; return y - (slope * x); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload