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

how to sort X Axis

3 Answers 143 Views
Chart
This is a migrated thread and some comments may be shown as answers.
christian
Top achievements
Rank 1
christian asked on 09 Sep 2009, 07:54 AM
Hi,

I have a multiple series bar chart and on the X-Axis I have datetime values. 
The series are all sorted by datetime but in the chart the X-Axis is not sorted. 
Do I have to set a sort on the X-Axis? If I have to do this can someone explain me how?

thx
christian 

3 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 11 Sep 2009, 02:31 PM
Hello Christian,

I believe we have sorted this out in the support ticket you have started. Let us know if further questions arise.

Greetings,
Ves
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
purdav
Top achievements
Rank 1
answered on 07 Jan 2010, 12:54 PM
Hi all,
I have the same request.. I would to sort x-axis data.
I' using this code to bind data to the chart:

                <telerikChart:RadChart x:Name="RadChart1"  
                                       Grid.Row="1"  
                                       Grid.Column="0"  
                                       Margin="0,12,0,0"  
                                       LegendStyle="{StaticResource legendStyle}" 
                                       telerik:StyleManager.Theme="Summer"


            EntityQuery<ContactCenter.Web.Call> ops1 = ctx.GetCallQuery(); 
            var op1 = ctx.Load(ops1); 
            op1.Completed += (sender1, e1) => 
            { 
                IEnumerable<FreeStat> res = from s in op1.Entities 
                                              group s by new 
                                              { 
                                                  Period = s.StartDate.ToString("yyyy-MM"), 
                                                  Agent = s.Agent.Name 
                                              } into grp 
                                              orderby grp.Key.Period ascending,  
                                                      grp.Key.Agent ascending 
                                              select new FreeStat 
                                              { 
                                                  Periodo = grp.Key.Period, 
                                                  Agente = grp.Key.Agent, 
                                                  Totale = grp.Count() 
                                              }; 
 
                SeriesMapping mapping1 = new SeriesMapping(); 
                mapping1.ItemMappings.Add(new ItemMapping("Totale", DataPointMember.YValue, ChartAggregateFunction.Sum)); 
                 
                BarSeriesDefinition bsd = new BarSeriesDefinition(); 
                bsd.ItemStyle = LayoutRoot.Resources["CustomStyle"as Style; 
                mapping1.SeriesDefinition = bsd; 
 
                mapping1.ItemMappings.Add(new ItemMapping("Periodo", DataPointMember.XCategory)); 
                mapping1.GroupingSettings.GroupDescriptors.Add(new ChartGroupDescriptor("Agente")); 
                mapping1.GroupingSettings.GroupDescriptors.Add(new ChartGroupDescriptor("Periodo")); 
 
                RadChart1.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Between; 
 
                RadChart1.SeriesMappings.Add(mapping1); 
                RadChart1.ItemsSource = res; 
            }; 
 

Unfortunately I have attached result (X-Axis is UNsorted)...
How can I sort X axis? Is there any kind of property to set?

Many thanks in advance!
Davide

0
Ves
Telerik team
answered on 12 Jan 2010, 09:21 AM
Hi DAVIDE,

RadChart does not allow this yet, but there is an easy way to sort the data in this case. Just leave the type of the Period property of the object you are grouping as DateTime, sort by it and convert it to string in the "select". This should do the trick:


IEnumerable<FreeStat> res = from s in op1.Entities
    group s by new
    {
        Period = s.StartDate,
        Agent = s.Agent.Name
    } into grp
    orderby grp.Key.Period ascending, 
    grp.Key.Agent ascending
    select new FreeStat
    {
        Periodo = grp.Key.Period.ToString("yyyy-MM"),
        Agente = grp.Key.Agent,
        Totale = grp.Count()
    };

In addition I would like to draw your attention to this help topic -- Categorical Charts. The idea behind categories is that a category is simply a string -- RadChart is not aware if it represents a date or not.

Best regards,
Ves
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Chart
Asked by
christian
Top achievements
Rank 1
Answers by
Ves
Telerik team
purdav
Top achievements
Rank 1
Share this question
or