Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 11-Jul-11 3:08am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
koolprasad2003 at 12-Jul-11 0:44am
   
Nice answer, My 5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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"]);
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 383
1 Richard Deeming 180
2 ChauhanAjay 176
3 Sergey Alexandrovich Kryukov 171
4 Yogesh Kumar Tyagi 165
0 Sergey Alexandrovich Kryukov 6,252
1 OriginalGriff 5,498
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 13 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100