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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Trendline slope and intercept are always zero

Thread ID:

Created:

Updated:

Platform:

Replies:

145296 Jun 16,2019 07:23 PM UTC Jun 17,2019 06:44 AM UTC UWP 1
loading
Tags: SfChart
Ben
Asked On June 16, 2019 07:23 PM UTC

Just as the title says: I can draw trendlines no problem, but when I try to access the Slope and Intercept properties, they're always zero.

My code produces the attached graph, and the following Debug.WriteLine() output:

Reference: Slope = 0, Intercept = 0
Measurement: Slope = 0, Intercept = 0

Here's the relevant code to add the trendlines and get to Slope and Intercept:

ReferenceScatterSeries.Trendlines.Clear();
MeasurementScatterSeries.Trendlines.Clear();

Trendline Trendline_R = new Trendline()
{
    Label = "Reference Cell",
    IsTrendlineVisible = true,
    Type = TrendlineType.Linear
};
Trendline Trendline_M = new Trendline()
{
    Label = "Measurement Cell",
    IsTrendlineVisible = true,
    Type = TrendlineType.Linear
};

ReferenceScatterSeries.Trendlines.Add(Trendline_R);
MeasurementScatterSeries.Trendlines.Add(Trendline_M);

Debug.WriteLine("Reference: Slope = " + Trendline_R.Slope.ToString() + ", Intercept = " + Trendline_R.Intercept.ToString());
Debug.WriteLine("Measurement: Slope = " + Trendline_M.Slope.ToString() + ", Intercept = " + Trendline_M.Intercept.ToString());

Attachment: Capture_3db2fd00.zip

Muneesh Kumar G [Syncfusion]
Replied On June 17, 2019 06:44 AM UTC

Hi Ben, 
 
Greetings from Syncfusion.  
 
We have analyzed your requirement and you can achieve this by getting trendline’s Slope and Intercept in SfChart’s loaded event as per the below code snippet.  
 
Code snippet 
 
  <syncfusion:SfChart x:Name="Chart" Margin="20" Loaded="Chart_Loaded"> 
 
 
 
 
Trendline Trendline_R, Trendline_M; 
        public MainPage() 
        { 
            this.InitializeComponent(); 
 
            Trendline_R = new Trendline() 
            { 
                Label = "Reference Cell", 
                IsTrendlineVisible = true, 
                Type = TrendlineType.Linear 
            }; 
 
            Trendline_M = new Trendline() 
            { 
                Label = "Measurement Cell", 
                IsTrendlineVisible = true, 
                Type = TrendlineType.Linear 
            }; 
             
            series1.Trendlines.Add(Trendline_R); 
            series2.Trendlines.Add(Trendline_M); 
 
         
        } 
 
        private void Chart_Loaded(object sender, RoutedEventArgs e) 
        { 
            Debug.WriteLine("Reference: Slope = " + Trendline_R.Slope.ToString() + ", Intercept = " + Trendline_R.Intercept.ToString()); 
            Debug.WriteLine("Measurement: Slope = " + Trendline_M.Slope.ToString() + ", Intercept = " + Trendline_M.Intercept.ToString()); 
 
        } 
 
 
Here we get the required details in loaded event, because SfChart needs some time to calculate their trendlines properties.  
 
We have prepared a sample based on this, please find the sample from the following location.  
 
 
Please let us know if you have any other queries.  
 
Regards, 
Muneesh Kumar G. 


CONFIRMATION

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

This page will automatically be redirected to the 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

Live Chat Icon For mobile
Live Chat Icon