Created
April 29, 2016 19:41
-
-
Save gmurray81/db909672c759d49dd647689f7a2c926c to your computer and use it in GitHub Desktop.
Plotting the intersection of two data sets as a scatter series.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Infragistics.Controls.Charts; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Documents; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
using System.Windows.Navigation; | |
using System.Windows.Shapes; | |
namespace WpfApplication4 | |
{ | |
/// <summary> | |
/// Interaction logic for MainWindow.xaml | |
/// </summary> | |
public partial class MainWindow : Window | |
{ | |
private TestData _testDataA; | |
private TestData _testDataB; | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
SetupTestData(); | |
var intersect = _testDataA.Intersect(_testDataB).ToList(); | |
var onlyA = _testDataA.Except(intersect).ToList(); | |
var onlyB = _testDataB.Except(intersect).ToList(); | |
var xAxis = new NumericXAxis(); | |
var yAxis = new NumericYAxis(); | |
var scatter1 = new ScatterSeries() | |
{ | |
Name = "onlyA", | |
Title = "Only A", | |
ItemsSource = onlyA, | |
XMemberPath = "XValue", | |
YMemberPath = "YValue", | |
XAxis = xAxis, | |
YAxis = yAxis | |
}; | |
var scatter2 = new ScatterSeries() | |
{ | |
Name = "onlyB", | |
Title = "Only B", | |
ItemsSource = onlyB, | |
XMemberPath = "XValue", | |
YMemberPath = "YValue", | |
XAxis = xAxis, | |
YAxis = yAxis | |
}; | |
var scatter3 = new ScatterSeries() | |
{ | |
Name = "intersect", | |
Title = "A Intersect B", | |
ItemsSource = intersect, | |
XMemberPath = "XValue", | |
YMemberPath = "YValue", | |
XAxis = xAxis, | |
YAxis = yAxis | |
}; | |
theChart.Axes.Add(xAxis); | |
theChart.Axes.Add(yAxis); | |
theChart.Series.Add(scatter1); | |
theChart.Series.Add(scatter2); | |
theChart.Series.Add(scatter3); | |
theChart.HorizontalZoomable = true; | |
theChart.VerticalZoomable = true; | |
} | |
private void SetupTestData() | |
{ | |
var testDataA = new TestData(); | |
var testDataB = new TestData(); | |
var testDataIntersection = new TestData(); | |
testDataA.AddRange(testDataIntersection); | |
testDataB.AddRange(testDataIntersection); | |
_testDataA = testDataA; | |
_testDataB = testDataB; | |
} | |
} | |
public class TestDataItem | |
{ | |
public string Label { get; set; } | |
public double XValue { get; set; } | |
public double YValue { get; set; } | |
public override int GetHashCode() | |
{ | |
var ret = Label != null ? Label.GetHashCode() : 0; | |
ret = ret + 17 * XValue.GetHashCode(); | |
ret = ret + 17 * YValue.GetHashCode(); | |
return ret; | |
} | |
public override bool Equals(object obj) | |
{ | |
if (obj == null && !(obj is TestDataItem)) | |
{ | |
return base.Equals(obj); | |
} | |
var other = (TestDataItem)obj; | |
return other.Label == Label && | |
other.XValue == XValue && | |
other.YValue == YValue; | |
} | |
} | |
public class TestData | |
: List<TestDataItem> | |
{ | |
private static Random _rand = new Random(); | |
public TestData() | |
{ | |
for (var i =0; i < 50; i++) | |
{ | |
Add(new TestDataItem() | |
{ | |
Label = i.ToString(), | |
XValue = _rand.NextDouble() * 100.0, | |
YValue = _rand.NextDouble() * 100.0 | |
}); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment