I'm using OxyPlot, you can get it here ... It's much nicer and easier to work with than WPF own solution (the charting dll they supply has NO documentation).
once you have it, in your code you can do:
// Create plot
var plot_model = new PlotModel() { Title = title};
// Create points
var points = from_a_method_linq_Sql_whatever();
var line_series = new LineSeries();
// Add plot to serie
foreach (var point in points)
line_series.Points.Add(point);
// Add them to the plot
plot_model.Series.Add(line_series);
I would have this plot as a property, and then simply bind to it from the XAML like this:
<oxy:Plot Model="{Binding OutputChart}" />
(make sure you have this on top of your xaml:
xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf"
You can also have your points exposed as a property and do all from the binding on the xaml. Your choice.
Adding axis and legends is simple as, just have a quick look at their documentation / forum.
Edit:
I've used something like this in an application I wrote:
// Running on a collection of objects that have dates and levels, and other things
foreach (var obj in lvl_reps)
{
points.Add(new ExercisePoint
{
DateTime = exercise.Date,
Lvl = obj.Level,
X = DateTimeAxis.ToDouble(exercise.Date.AddHours(-12)),
Y = obj.Reps.Sum(),
Exercise = exercise.Exercise
});
}
Don't let ExercisePoint scare you, here's the implementation of it:
/// <summary>
/// Extends the normal point used by OxyPlot to include the level and the date.
/// The Idea is to use them on the tool tip of the exercise
/// </summary>
class ExercisePoint : IDataPoint
{
public double X { get; set; }
public double Y { get; set; }
public int Lvl { get; set; }
public DateTime DateTime { get; set; }
public string Exercise { get; set; }
}
So this is how you can bind custom fields to points for example.