Click here to Skip to main content
12,953,937 members (51,463 online)
Rate this:
Please Sign up or sign in to vote.
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 11-Jul-11 3:08am
Rate this: bad
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.
koolprasad2003 12-Jul-11 0:44am
Nice answer, My 5
Rate this: bad
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["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"]);

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,464
CHill60 3,490
Maciej Los 3,123
ppolymorphe 2,020
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 13 Jul 2011
Copyright © CodeProject, 1999-2017
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