how to sort X Axis

4 posts, 0 answers
  1. christian
    christian avatar
    13 posts
    Member since:
    May 2009

    Posted 09 Sep 2009 Link to this post

    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 
  2. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 11 Sep 2009 Link to this post

    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.
  3. purdav
    purdav avatar
    26 posts
    Member since:
    Feb 2007

    Posted 07 Jan 2010 Link to this post

    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

  4. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 12 Jan 2010 Link to this post

    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.
Back to Top