DateTimeCategoricalAxis not grouping

3 posts, 1 answers
  1. Colter
    Colter avatar
    10 posts
    Member since:
    Apr 2013

    Posted 22 May 2013 Link to this post

    Hello Telerik,

    I've attached an image of a sample chart that I'm trying to construct.

    The dataset is simple: it's basically just a list of Crimes cooked up from random data.  What I'm trying to figure out is how to use the DataTimeComponent of the DateTimeCategorical axis.  I'm trying to group the occurances by month (irrespective of the year), but this is what I'm getting since it's grouping based on month but still sorting everything chronologically.  Do I have to do this grouping myself or is there some flag that I'm missing to do this?  i.e. I would like a group of bars for each month of the year instead of the chronologically sorted bars that I'm currently getting. (i.e. all of Jan grouped together, all of feb grouped together etc.)

    I suspect that I will have to do this aggregation on my own, but just thought i'd check to see if this is something that your ChartView should be able to do.
  2. Answer
    Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 27 May 2013 Link to this post

    Hi Colter,

    You can use regular CategoricalAxis and GenericDataPointBinding to extract only the month part of the DateTime:
    chart.Series.Add(new BarSeries
    {
      CombineMode = ChartSeriesCombineMode.Cluster,
      CategoryBinding = new GenericDataPointBinding<PlotInfo, string>()
          { ValueSelector = (pi) => pi.Date.ToString("MMM") },
      ValueBinding = new PropertyNameDataPointBinding("Value"),
      ItemsSource = GetTestData(new DateTime(2013, 1, 1)),
      LegendSettings = new SeriesLegendSettings() { Title = "Jan Sales" }
    });
       
    //where PlotInfo is a your data item:
    public class PlotInfo
    {
      public DateTime Date { get; set; }
      public double Value { get; set; }
    }

    I have attached a sample project to demonstrate.

    I hope this was helps.
     

    Regards,
    Petar Kirov
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Colter
    Colter avatar
    10 posts
    Member since:
    Apr 2013

    Posted 27 May 2013 Link to this post

    Petar,

    Thanks for the response.  I ended up doing something very similar but I like the way you did it better.  It's more elegant than my approach. 

    Regards,

    Colter
Back to Top