Hi,
Instead of a CategoryAxis -
CategoryAxis primaryAxis = new CategoryAxis();
primaryAxis.Title.Text = "Name";
chart.PrimaryAxis = primaryAxis;
I initialized a DateTimeCategoryAxis -
DateTimeCategoryAxis primaryAxis = new DateTimeCategoryAxis();
primaryAxis.Title.Text = "Name";
primaryAxis.LabelStyle.LabelFormat = "d/MMM/yy";
chart.PrimaryAxis = primaryAxis;
I also modified the Model and the ViewModel to -
public DateTime Name { get; set; }
public double Height { get; set; }
public Person(DateTime name, double height)
{
Name = name;
Height = height;
}
public class ViewModel
{
public ObservableCollection<Person> Data { get; set; }
public ViewModel()
{
Data = new ObservableCollection<Person>();
//Data.Add(new Person("David", 180));
//Data.Add(new Person("Michael", 170));
//Data.Add(new Person("Steve", 160));
//Data.Add(new Person("Joel", 182));
Data.Add(new Person(new DateTime(1998, 03, 03), 10));
Data.Add(new Person(new DateTime(1998, 04, 03), 10));
Data.Add(new Person(new DateTime(1999,05,03), 15));
Data.Add(new Person(new DateTime(2018, 10, 03), 95));
}
}
Now, if the dates are in order (1998,1998,1999,2016), the chart works just great. Please refer to the pic named dates_in_order.
Now if the I add another date - lets say from 2005 -
Data.Add(new Person(new DateTime(1998, 03, 03), 10));
Data.Add(new Person(new DateTime(1998, 04, 03), 10));
Data.Add(new Person(new DateTime(1999, 05,03), 15));
Data.Add(new Person(new DateTime(2016, 10, 03), 95));
Data.Add(new Person(new DateTime(2005, 10, 03), 105));
Please refer to the pic named dates_not_in_order.
There are two issues -
1) It does not create a new column between 1999 and 2016, but creates a column at the end after 2016. Any added data after 2005 - it treats the same way. Shouldn't the columns be with the dates in order - 1998, 1998, 1999, 2005, 2016, instead of 1998, 1998, 1999, 2016, 2005
2) The column does not have the appropriate label.
I am planning to pull data from a sqlite database and the dates are not sorted in anyway. I was under the assumption that when I use DateTimeCategoryAxis they will automatically place the dates in order just like one would expect when I use DateTimeAxis(). Please see third pic attached - dates_not_in_order_DateTimeAxis which looks quite ugly but the dates are in order.
Am I doing something wrong? Can you please modify your sample to include DateTimeCategory? If this is the way it normally behaves do you have any solutions in mind where I can keep equal spacing between different columns?
Attachment:
date_time_category_cb2357b0.zip