This is a migrated thread and some comments may be shown as answers.

DateTimeCategoricalAxis not grouping

2 Answers 55 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Colter
Top achievements
Rank 1
Colter asked on 22 May 2013, 11:36 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Petar Kirov
Telerik team
answered on 27 May 2013, 06:15 PM
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.

0
Colter
Top achievements
Rank 1
answered on 27 May 2013, 06:30 PM
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
Tags
ChartView
Asked by
Colter
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Colter
Top achievements
Rank 1
Share this question
or