如何使用Windows.Forms.DataVisualization.Charting控件在图形中绘制趋势线 [英] How to draw trendline in graph using Windows.Forms.DataVisualization.Charting control

查看:846
本文介绍了如何使用Windows.Forms.DataVisualization.Charting控件在图形中绘制趋势线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用System.Windows.Forms.DataVisualization.Charting绘制了图表

我需要在图形中绘制趋势线,

我怎么画呢?

有什么提示吗?

在此先感谢

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

推荐答案

计算代码中的趋势系数(有多种第三方统计信息库,如果您不想转录等式,可以执行此操作)并将其添加为新系列.据我所知,MS Chart控件不直接支持趋势线.

在绘制完所有主要序列并确定了轴的范围之后,您可能想计算直线的端点,因此趋势线会覆盖整个图表区域.
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.


是..after我得到了很多解决方案.以下代码段对我有用.

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


这篇关于如何使用Windows.Forms.DataVisualization.Charting控件在图形中绘制趋势线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆