Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have draw a chart using System.Windows.Forms.DataVisualization.Charting

I need to draw Trendline in graph,

how can i draw that ?

any hint ?

Thanks in advance
Posted

Yes..after lot of work around i got solution. following code snippet works for me.

chartCoRel.Series.Add("TrendLine");
                    chartCoRel.Series["TrendLine"].ChartType = SeriesChartType.Line;
                    chartCoRel.Series["TrendLine"].BorderWidth = 3;
                    chartCoRel.Series["TrendLine"].Color = Color.Red;
                    // Line of best fit is linear
                    string typeRegression = "Linear";//"Exponential";//
                    // The number of days for Forecasting
                    string forecasting = "1";
                    // Show Error as a range chart.
                    string error = "false";
                    // Show Forecasting Error as a range chart.
                    string forecastingError = "false";
                    // Formula parameters
                    string parameters = typeRegression + ',' + forecasting + ',' + error + ',' + forecastingError;
                    chartCoRel.Series[0].Sort(PointSortOrder.Ascending, "X");
                    // Create Forecasting Series.
                    chartCoRel.DataManipulator.FinancialFormula(FinancialFormula.Forecasting, parameters, chartCoRel.Series[0], chartCoRel.Series["TrendLine"]);
 
Share this answer
 
Comments
jchapin5 29-Apr-20 7:02am    
Thanks! This was very helpful.
Calculate the trend coefficients in code (there are various third party stats libraries which will do this if you don't feel like transcribing the equations) and add it as a new series. As far as I see, the MS Chart control does not support trend lines directly.

You probably want to calculate the endpoints of the line after you've drawn all your primary series and ranged the axes, so a trend line covers the whole chart area.
 
Share this answer
 
Comments
koolprasad2003 12-Jul-11 0:44am    
Nice answer, My 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900