Search results

Pyramid in ASP.NET MVC Accumulation Chart control

29 Jul 2021 / 1 minute to read

To render a pyramid series, use the series type as Pyramid.

razor
default.cs
Copied to clipboard
@Html.EJS().AccumulationChart("container").Series(series =>
            {
                series.DataSource(ViewBag.dataSource)
                      .XName("xValue")
                      .YName("yValue")
                      .Name("Browser")
                      .Type(Syncfusion.EJ2.Charts.AccumulationType.Pyramid).Add();
            })
            .EnableSmartLabels(true)
            .Title("Mobile Browser Statistics")
            .LegendSettings(ls => ls.Visible(false)).Render()
Copied to clipboard
public ActionResult Index()
        {
            List<PyramidChartData> chartData = new List<PyramidChartData>
            {

                new PyramidChartData { xValue = "Chrome", yValue = 37 },
                new PyramidChartData { xValue = "UC Browser", yValue = 17 },
                new PyramidChartData { xValue = "iPhone", yValue = 19 },
                new PyramidChartData { xValue = "Others", yValue = 14  },
                new PyramidChartData { xValue = "Opera", yValue = 11 },
                new PyramidChartData { xValue = "Android", yValue = 12 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class PyramidChartData
        {
            public string xValue;
            public double yValue;
        }

Mode

The Pyramid chart supports linear and surface modes of rendering. The default type of the pyramidMode is linear.

razor
mode.cs
Copied to clipboard
@Html.EJS().AccumulationChart("container").Series(series =>
            {
                series.DataSource(ViewBag.dataSource)
                      .XName("xValue")
                      .YName("yValue")
                      .Name("Browser")
                      .PyramidMode("Surface")
                      .Type(Syncfusion.EJ2.Charts.AccumulationType.Pyramid).Add();
            })
            .EnableSmartLabels(true)
            .Title("Mobile Browser Statistics")
            .LegendSettings(ls => ls.Visible(false)).Render()
Copied to clipboard
public ActionResult Index()
        {
            List<PyramidChartData> chartData = new List<PyramidChartData>
            {

                new PyramidChartData { xValue = "Chrome", yValue = 37 },
                new PyramidChartData { xValue = "UC Browser", yValue = 17 },
                new PyramidChartData { xValue = "iPhone", yValue = 19 },
                new PyramidChartData { xValue = "Others", yValue = 4  },
                new PyramidChartData { xValue = "Opera", yValue = 11 },
                new PyramidChartData { xValue = "Android", yValue = 12 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class PyramidChartData
        {
            public string xValue;
            public double yValue;
        }

Size

The size of the pyramid chart can be customized by using the width and height properties.

razor
size.cs
Copied to clipboard
@Html.EJS().AccumulationChart("container").Series(series =>
            {
                series.DataSource(ViewBag.dataSource)
                      .XName("xValue")
                      .YName("yValue")
                      .Name("Browser")
                      .Width("60%")
                      .Height("80%")
                      .Type(Syncfusion.EJ2.Charts.AccumulationType.Pyramid).Add();
            })
            .EnableSmartLabels(true)
            .Title("Mobile Browser Statistics")
            .LegendSettings(ls => ls.Visible(false)).Render()
Copied to clipboard
public ActionResult Index()
        {
            List<PyramidChartData> chartData = new List<PyramidChartData>
            {

                new PyramidChartData { xValue = "Chrome", yValue = 37 },
                new PyramidChartData { xValue = "UC Browser", yValue = 17 },
                new PyramidChartData { xValue = "iPhone", yValue = 19 },
                new PyramidChartData { xValue = "Others", yValue = 4  },
                new PyramidChartData { xValue = "Opera", yValue = 11 },
                new PyramidChartData { xValue = "Android", yValue = 12 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class PyramidChartData
        {
            public string xValue;
            public double yValue;
        }

Gap Between the Segments

Pyramid chart provides options to customize the space between the segments by using the gapRatio property of the series. It ranges from 0 to 1.

razor
gap.cs
Copied to clipboard
@Html.EJS().AccumulationChart("container").Series(series =>
            {
                series.DataSource(ViewBag.dataSource)
                      .XName("xValue")
                      .YName("yValue")
                      .Name("Browser")
                      .GapRatio(0.2)
                      .Type(Syncfusion.EJ2.Charts.AccumulationType.Pyramid).Add();
            })
            .EnableSmartLabels(true)
            .Title("Mobile Browser Statistics")
            .LegendSettings(ls => ls.Visible(false)).Render()
Copied to clipboard
public ActionResult Index()
        {
            List<PyramidChartData> chartData = new List<PyramidChartData>
            {

                new PyramidChartData { xValue = "Chrome", yValue = 37 },
                new PyramidChartData { xValue = "UC Browser", yValue = 17 },
                new PyramidChartData { xValue = "iPhone", yValue = 19 },
                new PyramidChartData { xValue = "Others", yValue = 4  },
                new PyramidChartData { xValue = "Opera", yValue = 11 },
                new PyramidChartData { xValue = "Android", yValue = 12 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class PyramidChartData
        {
            public string xValue;
            public double yValue;
        }

Explode

Points can be exploded on mouse click by setting the explode property to true. You can also explode the point on load using explodeIndex. Explode distance can be set by using explodeOffset property.

razor
explode.cs
Copied to clipboard
@Html.EJS().AccumulationChart("container").Series(series =>
            {
                series.DataSource(ViewBag.dataSource)
                      .XName("xValue")
                      .YName("yValue")
                      .Name("Browser")
                      .Explode(true)
                      .ExplodeOffset("10%")
                      .ExplodeIndex(0)
                      .ExplodeAll(false)
                      .Type(Syncfusion.EJ2.Charts.AccumulationType.Pyramid).Add();
            })
            .EnableSmartLabels(true)
            .Title("Mobile Browser Statistics")
            .LegendSettings(ls => ls.Visible(false)).Render()
Copied to clipboard
public ActionResult Index()
        {
            List<PyramidChartData> chartData = new List<PyramidChartData>
            {

                new PyramidChartData { xValue = "Chrome", yValue = 37 },
                new PyramidChartData { xValue = "UC Browser", yValue = 17 },
                new PyramidChartData { xValue = "iPhone", yValue = 19 },
                new PyramidChartData { xValue = "Others", yValue = 4  },
                new PyramidChartData { xValue = "Opera", yValue = 11 },
                new PyramidChartData { xValue = "Android", yValue = 12 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class PyramidChartData
        {
            public string xValue;
            public double yValue;
        }

Customization

Individual points can be customized using the pointRender event.

razor
custom.cs
Copied to clipboard
@Html.EJS().AccumulationChart("container").Series(series =>
            {
                series.DataSource(ViewBag.dataSource)
                      .XName("xValue")
                      .YName("yValue")
                      .Name("Browser")
                      .Type(Syncfusion.EJ2.Charts.AccumulationType.Pyramid).Add();
            })
            .EnableSmartLabels(true)
            .PointRender("pointRender")
            .Title("Mobile Browser Statistics")
            .LegendSettings(ls => ls.Visible(false)).Render()

<script>
            var pointRender = function (args) {
                if ((args.point.xValue as string).indexOf('iPhone') > -1) {
                    args.fill = '#f4bc42';
                     }
                       else {
                     args.fill = '#597cf9';
                     }
            };
</script>
Copied to clipboard
public ActionResult Index()
        {
            List<PyramidChartData> chartData = new List<PyramidChartData>
            {

                new PyramidChartData { xValue = "Chrome", yValue = 37 },
                new PyramidChartData { xValue = "UC Browser", yValue = 17 },
                new PyramidChartData { xValue = "iPhone", yValue = 19 },
                new PyramidChartData { xValue = "Others", yValue = 4  },
                new PyramidChartData { xValue = "Opera", yValue = 11 },
                new PyramidChartData { xValue = "Android", yValue = 12 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class PyramidChartData
        {
            public string xValue;
            public double yValue;
        }

See Also