# Trend line for Line chart in SSRS 2005

This article will help to draw the Trend Line for Line chart in SSRS 2005 .this was done through by calculating the data points for the specific data .the mathematical formula for find the trend line was Y=Mx+C.i was searched more links to solve this problem but i didnt get any solution. i tried this and now i got a clear trend for the line chart graph. i hope this will be useful.if any queries ask me ..

## Trend line for Line chart in SSRS 2005

I generate the Trend Line for SSRS 2005 for Line chart by creating the Stored procedure by using the Mathematical calculations.

This is the mathematical formula

By using this formula we are generate the trend line for given data for Line chart in SSRS 2005

M for slope

C for Intercept

Y for Trend

Y=Mx+C

M= n?(xy)- ?x?y

________________

n?(x)^2 -(?x)^2

C= ?y-m?x

_________

n

key_numorator is nothing but the slope numorator Part

key_denominator is nothing but the Slope Denominator part

key _slope is nothing but the slope of the given data

key__intercept is nothing but the Intercept for the given data

key_trend is nothing but the Trend for the given data

-------------------------------------------------------------------------------------------------------------------------------------------------
`set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgoALTER PROCEDURE [dbo].[Trend_Line_Chart]ASSET NOCOUNT ONBEGINtruncate table Trend_Line_chart_Table1_Tempinsert into Trend_Line_chart_Table1_TempSELECT * INTO Trend_Line_chart_Table1_Temp From Original_Value_Table--Now the Trend_Line_chart_Table1_Temp had the both x axix and Y axis --valuetruncate table Trend_Line_chart_Table2_Tempinsert into Trend_Line_chart_Table2_Tempselect count(*) as nvalue,xvalue as xaxis ,yvalue as yaxis, sum(xaxis*yaxis) as sum_xy,sum(yaxis) as sum_y,sum(x) as sum_x,sum(x*x) as total_xaxis,sum(sum(y)*sum(x)) as Sum_xy,(sum(x)*sum(x)) as sum_x_squ from Trend_Line_chart_Table1_Temp --This table is used to fetch the calculated field from temp_table1 and --its increse the performance select((select nvalue from Trend_Line_chart_Table2_Temp)*(select sum_xy from Trend_Line_chart_Table2_Temp))-((select sum_y from Trend_Line_chart_Table2_Temp)*(select sum_x from Trend_Line_chart_Table2_Temp)) as key_numorator ,((select nvalue from Trend_Line_chart_Table2_Temp)*(select total_xaxis from Trend_Line_chart_Table2_Temp))-(select sum_x from Trend_Line_chart_Table2_Temp)*(select sum_x from Trend_Line_chart_Table2_Temp) as key_denominator,(((select nvalue from Trend_Line_chart_Table2_Temp)*(select sum_xy from Trend_Line_chart_Table2_Temp))-((select sum_y from Trend_Line_chart_Table2_Temp)*(select sum_x from Trend_Line_chart_Table2_Temp)))*1.0/(((select nvalue from Trend_Line_chart_Table2_Temp)*(select total_xaxis from Trend_Line_chart_Table2_Temp))-(select sum_x from Trend_Line_chart_Table2_Temp)*(select sum_x from Trend_Line_chart_Table2_Temp)) as key _slope,((select sum_y from Trend_Line_chart_Table2_Temp)-((select sum_x from Trend_Line_chart_Table2_Temp)*(((select nvalue from Trend_Line_chart_Table2_Temp)*(select sum_xy from Trend_Line_chart_Table2_Temp))-((select sum_y from Trend_Line_chart_Table2_Temp)*(select sum_x from Trend_Line_chart_Table2_Temp)))*1.0/(((select nvalue from Trend_Line_chart_Table2_Temp)*(select total_xaxis from Trend_Line_chart_Table2_Temp))-(select sum_x from Trend_Line_chart_Table2_Temp)*(select sum_x from Trend_Line_chart_Table2_Temp))))/(select nvalue from Trend_Line_chart_Table2_Temp) as key__intercept,((((select nvalue from Trend_Line_chart_Table2_Temp)*(select sum_xy from Trend_Line_chart_Table2_Temp))-((select sum_y from Trend_Line_chart_Table2_Temp)*(select sum_x from Trend_Line_chart_Table2_Temp)))*1.0/(((select nvalue from Trend_Line_chart_Table2_Temp)*(select total_xaxis from Trend_Line_chart_Table2_Temp))-(select sum_x from Trend_Line_chart_Table2_Temp)*(select sum_x from Trend_Line_chart_Table2_Temp))*rowcnt)+((select sum_y from Trend_Line_chart_Table2_Temp)-((select sum_x from Trend_Line_chart_Table2_Temp)*(((select nvalue from Trend_Line_chart_Table2_Temp)*(select sum_xy from Trend_Line_chart_Table2_Temp))-((select sum_y from Trend_Line_chart_Table2_Temp)*(select sum_x from Trend_Line_chart_Table2_Temp)))*1.0/(((select nvalue from Trend_Line_chart_Table2_Temp)*(select total_xaxis from Trend_Line_chart_Table2_Temp))-(select sum_x from Trend_Line_chart_Table2_Temp)*(select sum_x from Trend_Line_chart_Table2_Temp))))/(select nvalue from Trend_Line_chart_Table2_Temp) as key_trend , Xaxis,Yaxisfrom Trend_Line_chart_Table1_Temp SET NOCOUNT OFFEnd `
--------------------------------------------------------------------------------