We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

calculatina linear regression function based on a scatter chart (i.e scatter chart values)

Thread ID:





55455 Jan 30,2007 04:20 PM UTC Feb 7,2007 04:00 PM UTC WinForms 2
Tags: Chart
Christian Fleischhacker
Asked On January 30, 2007 04:20 PM UTC

Hello! (VS.NET 2005; SyncF

Right now, i'm a little confused; I need to "port" an old access chart (done with some Microsoft chart control libary or so.) to our .net application using your control studio. However this control library offers me to do a scatter chart AND draw the linear regression function for this scatter on the chart area. However it seems that your chartcontrol/chart library doesn't have any similar functionality (i.e calculate the function formula -> calculating slope and Y-intercept, and display the line on the cart)

I know that you have supported functions for these calculation in *other* libraries (calculating and grid) However it seems that i need to create a lot of extra objects or classes to consume these functions (extra class that implements (ICalcData interface and i think either a gridmodel object or a spreadsheet object); So i would like to know:: Am i right with my assumption, that right now, there are no function inside the chart namespace that would allow me to calculate the formula for a linear regession, or have i overseen something?

If i am right, could you please think about this and implement basic functions to calculate these values to the chart namespace.

Administrator [Syncfusion]
Replied On February 6, 2007 07:40 AM UTC

Hi Christian,

My strong apologies for the delay in responding to you.

If you intention is to draw a Scatter Chart with TrendLine then it can done as shown in the code snippet below,

private void IntializeChartData( )
//Creates a new series
ChartSeries series1 = this.chartControl1.Model.NewSeries("Birds Age Record", ChartSeriesType.Scatter);
series1.Text = series1.Name;

//Add method is used to add points to the series
series1.Points.Add( 1.5, 3.0 );//series1.Points.Add(Xvalue,Yvalue)
series1.Points.Add( 2.5, 4.0 );
series1.Points.Add( 3.2, 8.0 );
series1.Points.Add( 4.5, 9.0 );
series1.Points.Add( 5.2, 10.0 );
series1.Points.Add( 6.8, 12.0 );
series1.Points.Add( 7.1, 14.0 );

//Series created is added to the chartcontrol
this.chartControl1.Series.Add( series1 );
this.chartControl1.Series[0].Style.Symbol.Color = Color.Orange;

//To set the Range of PrimaryYAxis
this.chartControl1.PrimaryYAxis.RangeType = ChartAxisRangeType.Set;

//Range of PrimaryYAxis
this.chartControl1.PrimaryYAxis.Range = new MinMaxInfo( 0, 15, 2 );

//Title to be displayed along PrimaryXAxis
this.chartControl1.PrimaryXAxis.Title = "Size of Wings of a Bird";

//Title to be displayed along PrimaryYAxis
this.chartControl1.PrimaryYAxis.Title = "Age in Days";

//Visibility of Grid of PrimaryXAxis and PrimaryYAxis
this.chartControl1.PrimaryXAxis.DrawGrid = false;
this.chartControl1.PrimaryYAxis.DrawGrid = false;

this.chartControl1.PrimaryXAxis.ForeColor = Color.Green;
this.chartControl1.PrimaryYAxis.ForeColor = Color.Green;

private void DrawTrendLineGraph( )
ChartSeries trend = this.chartControl1.Model.NewSeries( "Linear Trendline", ChartSeriesType.Line );
trend.Text = trend.Name;
count = this.chartControl1.Series[0].Points.Count;

double x1 = this.chartControl1.Series[0].Points[0].X;
double x2 = this.chartControl1.Series[0].Points[count - 1].X;

for (int i = 0; i < this.chartControl1.Series[0].Points.Count; i++)
AddPoint(this.chartControl1.Series[0].Points[i].X, this.chartControl1.Series[0].Points[i].YValues[0]);

m = (count * XY - (X * Y)) / (count * Xsqr - X * X);
b = (Y - m * X) / count;

trend.Points.Add(x1, ((m * x1) + b));
trend.Points.Add(x2, ((m * x2) + b));

this.chartControl1.Series.Add( trend );

Also kindly take a look at the attached sample.

Let me know if I am wrong in getting your requirement.

Thanks & Regards,


Christian Fleischhacker
Replied On February 7, 2007 04:00 PM UTC

Hi Ramya!
Yes I wanted to draw a Trendline to the scatter graph; Thanks for the code and the example.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon