Xamarin.Android | ComponentOne
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 DataCollection.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 class MainActivity : Activity
        {
            //int count = 1;
            private C1CollectionView<Item> cv;
            private C1Sunburst sunburst;
    
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);
                sunburst = new C1Sunburst(this);
                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();
                LinearLayout layout = new LinearLayout(this);
                LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);
                layout.AddView(sunburst, param);
    
                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);
    
                // Set our view from the "main" layout resource
                SetContentView(layout);
            }
            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;
            }
        }