Trendline polynomial equation

Hello, Syncfusion team!

I found your "Trend Line" sample very usefull, thanks for it! But I need to get equations of polynomial trendlines which are building in this sample (attached).

Is there any possibility to get it in explict form: y=a*x6+b*x5+c*x4+d*x3+e*x2+f*x+g?

Thanks, Ivan.


Attachment: Trend_Line_3f9ef49b.zip

1 Reply

SR Samuel Rajadurai Edwin Rajamanickam Syncfusion Team July 13, 2018 10:30 AM UTC

Hi Ivan, 
  
Thank you for using Syncfusion products. 
  
We have analyzed your requirement and we have updated the calculation method in trendline in sample with the PolynomialSlopes property as per the below code snippet. 
  
Code Snippet           
  
XAML 
  

        <chart:SfChart  LayoutUpdated="sfchart_LayoutUpdated"> 
        … 
        </chart:SfChart> 
 
 
  
C# 
  

    public partial class MainWindow : SampleLayoutWindow 
    { 
        bool isValueCalulated; 
 
        private void sfchart_LayoutUpdated(object sender, EventArgs e) 
        { 
            if (!isValueCalulated) 
                Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(CalculatePolynomialTrendline)); 
        } 
 
        private void CalculatePolynomialTrendline() 
        { 
            foreach (CartesianSeries series in this.sfchart.Series) 
            { 
                foreach (var trendline in series.Trendlines) 
                { 
                    var itemsSource = series.ItemsSource as ObservableCollection<Model>; 
                    for (int i = 0; i < (series.ItemsSource as ObservableCollection<Model>).Count; i++) 
                    { 
                        var x = i; 
                        var y = trendline.PolynomialSlopes.Select((t, index) => t * Math.Pow(x, (double)index)).Sum(); 
                    } 
                } 
 
                isValueCalulated = true; 
            } 
        } 
    } 

 
  
Please find the modified sample from the link below. 


Regards,
Samuel 


Loader.
Up arrow icon