Mick Posted March 23, 2009 Report Share Posted March 23, 2009 When I create a stacked area chart and I try to set the Y Axis max value, it appears to lose the data for any / all of the SeriesAttributes in the chart. Here is a quick mock up of the offending code, The single line that makes the difference is in red (second to last line of code): class DataPoint{ public DateTime Date { get; set; } public double Price { get; set; }}public Chart GetChart(){ Chart chart = new Chart(); chart.Gallery = Gallery.Area; chart.AxisX.Labels.Format = AxisFormat.Date; IList<DataPoint> points0 = new List<DataPoint>(); points0.Add(new DataPoint { Date = DateTime.Parse("1/1/2008"), Price = 1 }); points0.Add(new DataPoint { Date = DateTime.Parse("2/1/2008"), Price = 4 }); points0.Add(new DataPoint { Date = DateTime.Parse("3/1/2008"), Price = 2 }); SeriesAttributes series0 = new SeriesAttributes(); series0.Gallery = Gallery.Area; series0.Stacked = true; series0.ItemsSource = points0; series0.BindingPathX = "Date"; IList<DataPoint> points1 = new List<DataPoint>(); points1.Add(new DataPoint { Date = DateTime.Parse("1/1/2008"), Price = 1 }); points1.Add(new DataPoint { Date = DateTime.Parse("2/1/2008"), Price = 2 }); points1.Add(new DataPoint { Date = DateTime.Parse("3/1/2008"), Price = 1 }); SeriesAttributes series1 = new SeriesAttributes(); series1.Gallery = Gallery.Area; series1.Stacked = true; series1.ItemsSource = points1; series1.BindingPathX = "Date"; chart.Series.Add(series0); chart.Series.Add(series1); // This causes the chart to lose trackof the data it contains when uncommented chart.AxisX.Max = 10; return chart;}I stripped down this example to be as simple as possible, but perhaps I'm overlooking something. I need to be able to set the Y axis because it appears that the chart's algorithm attempts to do this automatically by selecting the max value of only one of the SeriesAttributes, rather than the max combined value of all SeriesAttributes (and data is cut off). Thank you, Mick Quote Link to comment Share on other sites More sharing options...
Mick Posted March 23, 2009 Author Report Share Posted March 23, 2009 Sorry the formatting is messed up - just disregard that chunk right above the red line. Thanks , Mick Quote Link to comment Share on other sites More sharing options...
JuanC Posted March 24, 2009 Report Share Posted March 24, 2009 There seems to be a typo in your code as you are setting the AxisX.Max instead of AxisY.Max. I tried using AxisY.Max and you will get the expected result. Regards, JuanC Quote Link to comment Share on other sites More sharing options...
Mick Posted March 24, 2009 Author Report Share Posted March 24, 2009 I'm sorry for the typo. I must have done some editing to my code after I pasted it from Visual Studio. I had actually implemented the change you suggest, and that was what was causing the original problem. The top chart looks exactly as I want it except for the Y axis scale, but when I manually set it I get the second picture. Setting the y axis is the only change that I make (I set it to 10). Perhaps you are on a newer build than I am? I am using 8.0.3309.21029. Thank you, Mick Quote Link to comment Share on other sites More sharing options...
JuanC Posted March 24, 2009 Report Share Posted March 24, 2009 I apologize as I did not focus on the Y data because I thought you were clipping the X axis. The easy fix for your scenario is to also set the AxisY.Min to 0. This should give you the right data in Y. Also you want to set the AllSeries.StackedStyle property to Stacked.Normal and you do not need to set each series Stacked property to true. chart.AllSeries.StackedStyle = StackedStyle.Normal;Please note that you are mixing stack with X values and we will not try to sync X values to stack, e.g. if you include a DataPoint in points1 for 2/15 we will not try to stack 3/1 against 3/1. Even if you can ensure both collections have the same number of points and the dates match please note that if you add points for 1/1/08, 2/1/08, 3/1/08 and 5/1/08, we will draw the point for 5/01/08 at twice the distance than the distance between 3/1 and 2/1 If your dates are not equally spaced but you want the X axis to be equally spaced then you will have to set the data on a global basis instead of per-series, e.g. IList<DataPoint> points = new List<DataPoint>();points.Add(new DataPoint { Date = DateTime.Parse("1/1/2008"), Price = 1, Price2 = 1 });points.Add(new DataPoint { Date = DateTime.Parse("2/1/2008"), Price = 4, Price2 = 2 });points.Add(new DataPoint { Date = DateTime.Parse("3/1/2008"), Price = 2, Price2 = 1 });points.Add(new DataPoint { Date = DateTime.Parse("5/1/2008"), Price = 2, Price2 = 1 });SeriesAttributes series0 = new SeriesAttributes();series0.BindingPath = "Price";SeriesAttributes series1 = new SeriesAttributes();series1.BindingPath = "Price2";chart.Series.Add(series0);chart.Series.Add(series1);chart.AxisX.Labels.BindingPath = "Date";chart.ItemsSource = points;This assumes that you can mix in one CLR object the data for both series. Regards, JuanC Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.