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. Image for the cookie policy date
close icon

Trying to set series data programatically with WPF chart

Why doesn't this work? The axes don't scale and the line never plots... I'm lost...

CODE BEHIND:

public class TimePoint
{
public DateTime X { get; set; }
public DateTime Y { get; set; }
}

public void AddSeries()
{
ObservableCollection points = new
ObservableCollection();

points.Add(new TimePoint{X = new DateTime(2010, 1, 1), Y = 5 });
points.Add(new TimePoint{X = new DateTime(2010, 1, 2), Y = 15 });
points.Add(new TimePoint{X = new DateTime(2010, 1, 3), Y = 5 });
points.Add(new TimePoint{X = new DateTime(2010, 1, 4), Y = 35 });
points.Add(new TimePoint{X = new DateTime(2010, 1, 5), Y = 5 });

ChartSeries s = new ChartSeries(ChartTypes.FastLine);
s.StrokeThickness = 2;
s.BindingPathX = "X";
s.BindingPathsY = new List { "Y" };
s.DataSource = points;
chart1.Areas[0].Series.Add(s);
}


XAML:






DateTimeInterval="1.00:00:00" ValueType="DateTime" />












3 Replies

SN Senthilkumar N Syncfusion Team November 18, 2010 05:31 AM UTC

Hi John,

Thanks for choosing Syncfusion products.

The Definition of value type for Y Property is set as DateTime. But it is initialized as integer in ObservableCollection. This makes the chart not rendered. I have modified your code like following:

The modified sample code snippet is:

public class TimePoint
{
public DateTime X { get; set; }
public int Y { get; set; }
}

I have attached a sample illustrating this and the sample can be obtained from the following location.

http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=97308163757423.zip

Let me know if you have any queries.

Regards,
Senthilkumar




JF John Fairbanks November 18, 2010 03:12 PM UTC

I knew I must be doing something stupid! Thanks! :-)



SN Senthilkumar N Syncfusion Team November 19, 2010 05:10 AM UTC

Hi John,

We are glad to hear that your problem has been resolved. Please do not hesitate to open a new support incident if you ever need further assistance from us.

Thanks for choosing Syncfusion Products.

Regards,
Senthilkumar



Loader.
Live Chat Icon For mobile
Up arrow icon