Log in to like this post! Introduction to Series Data Correlation with XamDataChart Damyan Petev / Friday, November 11, 2011 This is one of the new features for you to take advantage of with the new release and it is a cooperation between the XamDataChart control and the CorrelationCalculator which is part of the Infragistics Math Calculators™ library. This integration provides a simple way to calculate correlation between two values in a data set displayed using the Scatter Series. The CorrelationCalculator calculates what is referred in statistics as the Pearson product-moment correlation coefficient - used to measure the linear association(correlation) between two variables (X and Y) in a data set with a value between +1 and −1. The closer to those marks the coefficient is the stronger the relationship between them. For example you can plot data for electricity usage spikes and cold weather and sure enough you will notice a dependence. If you are interested to read more on that you can find sufficient explanations in our documentation - especially the CorrelationCalculator page where you can find the formulas and see a comparison of types of correlation based on the coefficient with visual examples. And of course there’s an extensive article on Wikipedia right here. The Correlation calculator Considering what it does this element doesn’t have a visual representation so naturally it would be defined in the sources section of the control, page or even the application. And since it calculates correlation it would require a data set(ItemsSource) and two variables to compare. Before we get to that as always you should add some assembly references – the shared InfragisticsSL4.v11.2.dll, then InfragisticsSL4.Math.v11.2.dll and InfragisticsSL4.Math.Calculators.v11.2.dll for the calculator and since we’ll use a XamDataChart you might as well add InfragisticsSL4.Controls.Charts.XamDataChart.v11.2.dll. Add the obligatory namespace in XAML: xmlns:ig="http://schemas.infragistics.com/xaml" At this point you set up the CorrelationCalculator and for presentation purposes we will use sample data generated by the CorrelationDataSample object, the code for which is made available in Visual Basic and C# on this page. Let’s add two different types of generated data and a calculator for each, bind its ItemsSource to them and provide paths for both values to be compared. In this case the generated data is created with X and Y: <UserControl.Resources> <ResourceDictionary> <!--Random data--> <local:CorrelationDataSample x:Key="randomData"> <local:CorrelationDataSample.Settings> <local:CorrelationDataSettings DataDistribution="Random" DataPoints='100'/> </local:CorrelationDataSample.Settings> </local:CorrelationDataSample> <!--Data that is random and increasing--> <local:CorrelationDataSample x:Key="randomIncreasing"> <local:CorrelationDataSample.Settings> <local:CorrelationDataSettings DataDistribution="RandomlyIncreasing" DataPoints='100'/> </local:CorrelationDataSample.Settings> </local:CorrelationDataSample> <!--Define calculator for the random data--> <ig:CorrelationCalculator x:Key="correlCalc" XMemberPath="X" YMemberPath="Y" ItemsSource="{StaticResource randomData}"/> <!--Define calculator for the randomly increasing data--> <ig:CorrelationCalculator x:Key="correlCalc2" XMemberPath="X" YMemberPath="Y" ItemsSource="{StaticResource randomIncreasing}"/> </ResourceDictionary> </UserControl.Resources> The Chart At this point you have data, a calculator that has computed the correlation coefficient for the two members and all that is left is to display that data with simplicity and style using a XamDataChart Scatter series for each type of generated data. One efficient way to do that is bind the Title property of the series to the corresponding calculators’ Value: <ig:XamDataChart Legend="{Binding ElementName=legend}"> <ig:XamDataChart.Axes> <ig:NumericXAxis x:Name="xAxis" /> <ig:NumericYAxis x:Name="yAxis" /> </ig:XamDataChart.Axes> <ig:XamDataChart.Series> <ig:ScatterSeries Title="{Binding Value, Source={StaticResource correlCalc}}" ItemsSource="{StaticResource randomData}" XMemberPath="X" YMemberPath="Y" XAxis="{Binding ElementName=xAxis}" YAxis="{Binding ElementName=yAxis}"/> <ig:ScatterSeries Title="{Binding Value, Source={StaticResource correlCalc2}}" ItemsSource="{StaticResource randomIncreasing}" XMemberPath="X" YMemberPath="Y" XAxis="{Binding ElementName=xAxis}" YAxis="{Binding ElementName=yAxis}" MarkerBrush="#DB8ED465" MarkerOutline="#54004B00" /> </ig:XamDataChart.Series> </ig:XamDataChart> As you noticed on the very first row we defined a legend property for the chart so add a legend element too: <ig:Legend Name="legend" Content="Data Correlation"/> Then again the calculators’ results are available for you to display as you see fit but why would use something else when the end result can look like this: The blue series are the random data and the green are the randomly increasing data. As a side effect of using generated data you can actually tell how random ‘random’ really is - remember values closer to zero mean less correlation and this one is pretty low. I’ll admit this is one of the more close-to-perfect screenshots. Check out our Silverlight online samples on this or download the offline WPF samples from here and if you want a project to try yourself – as always there’s one available here. The demo solution includes a Silverlight project and the same code in a WPF project just for the sake of reminding this is a XAML Cross-platform example after all. Note: The solution has been cleaned so make sure the references are all in check and then build it.