12,953,937 members (51,463 online)
Rate this:
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 ?

Posted 11-Jul-11 3:08am

Rate this:

## 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.

Rate this:

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

Top Experts
Last 24hrsThis month
 ppolymorphe 110 OriginalGriff 105 Kornfeld Eliyahu Peter 80 Dave Kreskowiak 73 RickZeeland 70
 OriginalGriff 6,464 CHill60 3,490 Maciej Los 3,123 ppolymorphe 2,020 Jochen Arndt 1,975