Grouping

24 Feb 202224 minutes to read

You can club/group few points of the series based on GroupTo property. For example, if the club value is 11, then the points with value less than 11 is grouped together and will be showed as a single point with label others. The property also takes value in percentage (percentage of total data points value).

@Html.EJS().AccumulationChart("container")
                    .Series(sr =>
                    {
                        sr.Type(Syncfusion.EJ2.Charts.AccumulationType.Pie)
                               .XName("xValue")
                               .YName("yValue")
                               .Name("RIO")
                               .Animation(ViewBag.animation)
                               .DataSource(ViewBag.dataSource)
                               .GroupTo("10").Add();
                    })
                     .EnableSmartLabels(true)
                     .LegendSettings(leg => leg.Visible(false))
                     .Title("RIO Olympics Gold").Render()
public IActionResult Index()
        {
            List<GroupingChartData> chartData = new List<GroupingChartData>
            {
                new GroupingChartData { xValue = "China", yValue = 26, text = "China: 26" },
                new GroupingChartData { xValue = "Russia", yValue = 19, text = "Russia: 19" },
                new GroupingChartData { xValue = "Germany", yValue = 17, text = "Germany: 17" },
                new GroupingChartData { xValue = "Japan", yValue = 12, text = "Japan: 12" },
                new GroupingChartData { xValue = "France", yValue = 10, text = "France: 10" },
                new GroupingChartData { xValue = "South Korea", yValue = 9,  text = "South Korea: 9" },
                new GroupingChartData { xValue = "Great Britain", yValue = 27, text = "Great Britain: 27" },
                new GroupingChartData { xValue = "Italy", yValue = 8,  text = "Italy: 8" },
                new GroupingChartData { xValue = "Australia", yValue = 8,  text = "Australia: 8" },
                new GroupingChartData { xValue = "Netherlands", yValue = 8,  text = "Netherlands: 8" },
                new GroupingChartData { xValue = "Hungary", yValue = 8,  text = "Hungary: 8" },
                new GroupingChartData { xValue = "Brazil",  yValue = 7,  text = "Brazil: 7" },
                new GroupingChartData { xValue = "Spain",   yValue = 7,  text = "Spain: 7" },
                new GroupingChartData { xValue = "Kenya",   yValue = 6,  text = "Kenya: 6" }

            };
            ViewBag.dataSource = chartData;
            
            return View();
        }
        public class GroupingChartData
        {
            public string xValue;
            public double yValue;
            public string text;
        }

Pie Grouping

Broken Slice

You can visualize all points available in club/group points by clicking on the grouped point. For example, if 5 points are grouped together it will be showed as a single slice with label others. If we click on others slice it will explode and broke into 5 seperate slices.

@(Html.EJS().AccumulationChart("container")
    .Series(sr =>
        {
            sr.Type(Syncfusion.EJ2.Charts.AccumulationType.Pie)
            .XName("xValue")
            .YName("yValue")
            .Name("RIO")
            .Explode(true)
            .DataLabel(dl => dl.Visible(true).Name("text").Position(Syncfusion.EJ2.Charts.AccumulationLabelPosition.Outside).ConnectorStyle(cs=>cs.Type(Syncfusion.EJ2.Charts.ConnectorType.Line).Length("5%")).Font(ft => ft.Size("14px")))
            .Animation(animate => animate.Enable(false))
            .Radius("70%")
            .StartAngle(0)
            .EndAngle(360)
            .InnerRadius("0%")
            .GroupTo("9")
            .GroupMode(Syncfusion.EJ2.Charts.GroupModes.Point)
            .DataSource(ViewBag.dataSource).Add();
        })
    .EnableSmartLabels(true)
    .Tooltip(tp => tp.Enable(false))
    .LegendSettings(leg => leg.Visible(false))
    .Title("RIO Olympics Gold").Render()
)
public ActionResult Index()
{
    List<GroupingChartData> chartData = new List<GroupingChartData>
    {
        new GroupingChartData { xValue = "China",         yValue = 26, text = "China: 26" },
        new GroupingChartData { xValue = "Russia",        yValue = 19, text = "Russia: 19" },
        new GroupingChartData { xValue = "Germany",       yValue = 17, text = "Germany: 17" },
        new GroupingChartData { xValue = "Japan",         yValue = 12, text = "Japan: 12" },
        new GroupingChartData { xValue = "France",        yValue = 10, text = "France: 10" },
        new GroupingChartData { xValue = "South Korea",   yValue = 9,  text = "South Korea: 9" },
        new GroupingChartData { xValue = "Great Britain", yValue = 27, text = "Great Britain: 27" },
        new GroupingChartData { xValue = "Italy",         yValue = 8,  text = "Italy: 8" },
        new GroupingChartData { xValue = "Australia",     yValue = 8,  text = "Australia: 8" },
        new GroupingChartData { xValue = "Netherlands",   yValue = 8,  text = "Netherlands: 8" },
        new GroupingChartData { xValue = "Hungary",       yValue = 8,  text = "Hungary: 8" },
        new GroupingChartData { xValue = "Brazil",        yValue = 7,  text = "Brazil: 7" },
        new GroupingChartData { xValue = "Spain",         yValue = 7,  text = "Spain: 7" },
        new GroupingChartData { xValue = "Kenya",         yValue = 6,  text = "Kenya: 6" }
    };
    ViewBag.animation = new ChartAnimation { Enable = true };
    ViewBag.dataSource = chartData;
    return View();
}

public class GroupingChartData
{
    public string xValue;
    public double yValue;
    public string text;
}

Group Mode

Slice can also be grouped based on number of points by specifying the GroupMode to Point. For example, if the group to value is 11, accumulation chart will show 1st 11 points and will group remaining entries in the collection as a single point.

@(Html.EJS().AccumulationChart("container")
    .Series(sr =>
    {
        sr.Type(Syncfusion.EJ2.Charts.AccumulationType.Pie)
            .XName("xValue")
            .YName("yValue")
            .Name("RIO")
            .Explode(true)
            .DataLabel(dl => dl.Visible(true).Name("text").Position(Syncfusion.EJ2.Charts.AccumulationLabelPosition.Outside).ConnectorStyle(cs=>cs.Type(Syncfusion.EJ2.Charts.ConnectorType.Line).Length("5%")).Font(ft => ft.Size("14px")))
            .Animation(animate => animate.Enable(false))
            .Radius("70%")
            .StartAngle(0)
            .EndAngle(360)
            .InnerRadius("0%")
            .GroupTo("3")
            .GroupMode(Syncfusion.EJ2.Charts.GroupModes.Point)
            .DataSource(ViewBag.dataSource).Add();
    })
    .EnableSmartLabels(true)
    .Tooltip(tp => tp.Enable(false))
    .LegendSettings(leg => leg.Visible(false))
    .Title("RIO Olympics Gold").Render()
)
public ActionResult Index()
        {
            List<GroupingChartData> chartData = new List<GroupingChartData>
            {

                new GroupingChartData { xValue = "China",         yValue = 26, text = "China: 26" },
                new GroupingChartData { xValue = "Russia",        yValue = 19, text = "Russia: 19" },
                new GroupingChartData { xValue = "Germany",       yValue = 17, text = "Germany: 17" },
                new GroupingChartData { xValue = "Japan",         yValue = 12, text = "Japan: 12" },
                new GroupingChartData { xValue = "France",        yValue = 10, text = "France: 10" },
                new GroupingChartData { xValue = "South Korea",   yValue = 9,  text = "South Korea: 9" },
                new GroupingChartData { xValue = "Great Britain", yValue = 27, text = "Great Britain: 27" },
                new GroupingChartData { xValue = "Italy",         yValue = 8,  text = "Italy: 8" },
                new GroupingChartData { xValue = "Australia",     yValue = 8,  text = "Australia: 8" },
                new GroupingChartData { xValue = "Netherlands",   yValue = 8,  text = "Netherlands: 8" },
                new GroupingChartData { xValue = "Hungary",       yValue = 8,  text = "Hungary: 8" },
                new GroupingChartData { xValue = "Brazil",        yValue = 7,  text = "Brazil: 7" },
                new GroupingChartData { xValue = "Spain",         yValue = 7,  text = "Spain: 7" },
                new GroupingChartData { xValue = "Kenya",         yValue = 6,  text = "Kenya: 6" }

            };
            ViewBag.animation = new ChartAnimation { Enable = true };
            ViewBag.dataSource = chartData;
            return View();
        }

        public class GroupingChartData
        {
            public string xValue;
            public double yValue;
            public string text;
        }

Customization

You can customize the grouped point and its data label using PointRender and TextRender event.

@Html.EJS().AccumulationChart("container")
                    .Series(sr =>
                    {
                        sr.Type(Syncfusion.EJ2.Charts.AccumulationType.Pie)
                               .XName("xValue")
                               .YName("yValue")
                               .Name("RIO")
                               .Animation(ViewBag.animation)
                               .DataSource(ViewBag.dataSource)
                               .GroupTo("10")
                               .DataLabel(ViewBag.dataLabel).Add();
                    })
                     .EnableSmartLabels(true)
                     .LegendSettings(leg => leg.Visible(false))
                     .PointRender("pointRender").TextRender("textRender")
                     .Title("RIO Olympics Gold").Render()

<script>
        var pointRender = function(args) {
           if ((args.point.x as string).indexOf('Others') > -1) {
            args.fill = '#D3D3D3';
        }
        }
        var textRender = function(args) {
            if (args.text.indexOf('Others') > -1) {
            args.text = 'Grouped Slices';
            args.color = 'red';
            args.border.width = 1;
        }
        }
</script>
public ActionResult Index()
        {
           List<GroupingChartData> chartData = new List<GroupingChartData>
            {
                new GroupingChartData { xValue = "China", yValue = 26, text = "China: 26" },
                new GroupingChartData { xValue = "Russia", yValue = 19, text = "Russia: 19" },
                new GroupingChartData { xValue = "Germany", yValue = 17, text = "Germany: 17" },
                new GroupingChartData { xValue = "Japan", yValue = 12, text = "Japan: 12" },
                new GroupingChartData { xValue = "France", yValue = 10, text = "France: 10" },
                new GroupingChartData { xValue = "South Korea", yValue = 9,  text = "South Korea: 9" },
                new GroupingChartData { xValue = "Great Britain", yValue = 27, text = "Great Britain: 27" },
                new GroupingChartData { xValue = "Italy", yValue = 8,  text = "Italy: 8" },
                new GroupingChartData { xValue = "Australia", yValue = 8,  text = "Australia: 8" },
                new GroupingChartData { xValue = "Netherlands", yValue = 8,  text = "Netherlands: 8" },
                new GroupingChartData { xValue = "Hungary", yValue = 8,  text = "Hungary: 8" },
                new GroupingChartData { xValue = "Brazil",  yValue = 7,  text = "Brazil: 7" },
                new GroupingChartData { xValue = "Spain",   yValue = 7,  text = "Spain: 7" },
                new GroupingChartData { xValue = "Kenya",   yValue = 6,  text = "Kenya: 6" }

            };
            ViewBag.dataSource = chartData;
            
            return View();
        }
        public class GroupingChartData
        {
            public string xValue;
            public double yValue;
            public string text;
        }