Xamarin.Android のドキュメント
グループ化
コントロール > Sunburst > 機能 > グループ化

CollectionView クラスは、.NET と類似の ICollectionView インタフェースを介してグループ化をサポートしています。グループ化を有効にするには、1 つ以上の GroupDescription オブジェクトを CollectionView.GroupDescription プロパティに追加します。GroupDescription オブジェクトは柔軟であり、値またはグループ化関数に基づいてデータをグループ化できます。次のコードは GroupChanged イベントと SortChanged イベントを使用して、Sunburst チャートでグループ化操作を実行します。

次の図は、Sunburst チャートコントロールでグループ化を設定する方法を示します。

次のコード例は、これらのプロパティを設定する方法を示します。この例では、「クイックスタート」セクションで作成したデータを使用します。

CS
コードのコピー
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;

            //ソートは現在の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);

            // 「メイン」レイアウトリソースからビューを設定する
            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;
        }
    }