ComponentOne Xamarin.iOS Documentation
Controls / Sunburst Chart / Features / Grouping
In This Topic
    Grouping
    In This Topic

    The CollectionView class supports grouping through the ICollectionView interface, similar to the one in .NET. To enable grouping, add one or more GroupDescription objects to the CollectionView.GroupDescription property. GroupDescription objects are flexible, allowing you to group data based on value or on grouping functions. The below code uses the GroupChanged event and SortChanged event for performing grouping operation on Sunburst Chart.

    The image below shows how to set Grouping in Sunburst Chart control.

    The following code example demonstrates how to set these properties using C#. This examples uses the data created in the Quick Start section.

    CS
    Copy Code
    public partial class ViewController : UIViewController
        {
            private C1CollectionView<Item> cv;
            public ViewController(IntPtr handle) : base(handle)
            {
            }
            public override void ViewDidLoad()
            {
                base.ViewDidLoad();
                // Perform any additional setup after loading the view, typically from a nib.
                sunburst = new C1Sunburst();
                sunburst.Binding = "Value";
                sunburst.BindingName = "Year,Quarter,Month";
                sunburst.ToolTipContent = "{}{name}\n{y}";
                sunburst.DataLabel.Position = PieLabelPosition.Center;
                sunburst.DataLabel.Content = "{}{name}";
                cv = DataService.CreateGroupCVData();
                this.Add(sunburst);
    
                cv.GroupChanged += View_GroupChanged;
                cv.SortChanged += Cv_SortChanged;
    
                //Sort cannot work synchronize with group in current CollectionView
                SortDescription yearSortDescription = new SortDescription("Year", SortDirection.Ascending);
                SortDescription quarterSortDescription = new SortDescription("Quarter", SortDirection.Ascending);
                SortDescription monthSortDescription = new SortDescription("MonthValue", SortDirection.Ascending);
                SortDescription[] sortDescriptions = new SortDescription[] { yearSortDescription, quarterSortDescription, monthSortDescription };
                cv.SortAsync(sortDescriptions);
            }
            private void Cv_SortChanged(object sender, System.EventArgs e)
            {
                GroupDescription yearGroupDescription = new GroupDescription("Year");
                GroupDescription quarterGroupDescription = new GroupDescription("Quarter");
                GroupDescription monthGroupDescription = new GroupDescription("MonthName");
                GroupDescription[] groupDescriptions = new GroupDescription[] { yearGroupDescription, quarterGroupDescription, monthGroupDescription };
                cv.GroupAsync(groupDescriptions);
            }
    
            private void View_GroupChanged(object sender, System.EventArgs e)
            {
                this.sunburst.ItemsSource = cv;
                CGRect rect = new CGRect(this.View.Frame.X, this.View.Frame.Y + 80,
                                         this.View.Frame.Width, this.View.Frame.Height - 80);
    
                sunburst.Frame = new CGRect(rect.X, rect.Y, rect.Width, rect.Height - 10);
            }
            public override void ViewDidLayoutSubviews()
            {
                base.ViewDidLayoutSubviews();
    
                sunburst.Frame = new CGRect(this.View.Frame.X, this.View.Frame.Y,
                                         this.View.Frame.Width, this.View.Frame.Height);
            }