12,395,115 members (67,374 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
 OriginalGriff 215 ppolymorphe 165 Richard Deeming 120 Jochen Arndt 110 Richard MacCutchan 90
 OriginalGriff 5,998 Karthik Bangalore 2,382 ppolymorphe 2,350 F-ES Sitecore 1,877 Richard MacCutchan 1,707