# chart-stacked-column

> Stacked Column chart of country-level cotton production from 2019-2024 with legend-driven corners.

**Framework:** aspnet-mvc  **Component:** Chart  **Variant:** stacked-column

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/aspnet-mvc/chart-stacked-column.json
```

**Install Package(s)**

```bash
Install-Package Syncfusion.AspNetMvc.Charts
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/chart-stacked-column/Chart.cshtml

```cshtml
@using Syncfusion.EJ2;
@section ControlsSection{
    <div class="control-section" align="center">
        
      @Html.EJS().Chart("container-vertical").Series(series =>
 {
     series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingColumn).XName("X").YName("Y").DataSource(ViewData["ChartPoints"]).Border(br => br.Width(1).Color("#ffffff")).Name("India").LegendShape(Syncfusion.EJ2.Charts.LegendShape.Rectangle).ColumnWidth(0.4).Marker(marker => marker.Visible(false).DataLabel(dl => dl.Visible(true).Font(ft => ft.Size("13px")))).Add();
     series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingColumn).XName("X").YName("Y").DataSource(ViewData["ChartPoints1"]).Border(br => br.Width(1).Color("#ffffff")).Name("China").LegendShape(Syncfusion.EJ2.Charts.LegendShape.Rectangle).ColumnWidth(0.4).Marker(marker => marker.Visible(false).DataLabel(dl => dl.Visible(true).Font(ft => ft.Size("13px")))).Add();
     series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingColumn).XName("X").YName("Y").DataSource(ViewData["ChartPoints2"]).Border(br => br.Width(1).Color("#ffffff")).Name("United States").LegendShape(Syncfusion.EJ2.Charts.LegendShape.Rectangle).ColumnWidth(0.4).Marker(marker => marker.Visible(false).DataLabel(dl => dl.Visible(true).Font(ft => ft.Size("13px")))).CornerRadius(cr => cr.TopLeft(4).TopRight(4)).Add();
 }).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
 .MajorGridLines(mg=>mg.Width(0)).MinorGridLines(mg => mg.Width(0))
 .MajorTickLines(mt => mt.Width(0)).
 MinorTickLines(mt => mt.Width(0)).LineStyle(ls => ls.Width(0)).Interval(1)
 .LabelIntersectAction(Syncfusion.EJ2.Charts.LabelIntersectAction.Rotate45)
       ).PrimaryYAxis(py => py.MajorTickLines(mt => mt.Width(0)).
       MinorTickLines(mt => mt.Width(0)).MinorGridLines(mg => mg.Width(1)).LineStyle(ls => ls.Width(0)).Title("Production (60KG Bags)").LabelFormat("{value}M").Interval(20)
       ).Title("Global Cotton Production by Country (2019-2024)").SubTitle("Source: fas.usda.gov").ChartArea(area => area.Border(br => br.Width(0)).Margin(mr => mr.Bottom(12))).Tooltip(tt => tt.Enable(true).EnableHighlight(true).Header("<b>${point.x}</b>").Format("${series.name} : <b>${point.y}</b>")).Load("load").LegendClick("onLegendClick").AxisLabelRender("axisLabelRender").StackLabels(stackLabels => stackLabels.Visible(true).Format("{value}M")).LegendSettings(leg => leg.Visible(true).EnableHighlight(true).ShapeHeight(8).ShapeWidth(8)).Render()
        </div>

    @*custom code start*@
    <style>
        #control-container {
            padding: 0px !important;
        }
    </style>
    @*custom code end*@
    <script src="~/Scripts/chart/theme-color.js"></script>
    <script>
        var load = function (args) {
            loadChartTheme(args);
            args.chart.width = ej.base.Browser.isDevice ? "100%" : "75%";
        }
        var onLegendClick = function (args) {
            if (args.series.index === 0) {
                if (args.chart.series[2].visible) {
                    args.chart.series[2].cornerRadius.topLeft = 4;
                    args.chart.series[2].cornerRadius.topRight = 4;
                    args.chart.series[0].cornerRadius.topLeft = 0;
                    args.chart.series[0].cornerRadius.topRight = 0;
                } else if (args.chart.series[1].visible) {
                    args.chart.series[1].cornerRadius.topLeft = 4;
                    args.chart.series[1].cornerRadius.topRight = 4;
                    args.chart.series[0].cornerRadius.topLeft = 0;
                    args.chart.series[0].cornerRadius.topRight = 0;
                } else {
                    args.chart.series[0].cornerRadius.topLeft = 4;
                    args.chart.series[0].cornerRadius.topRight = 4;
                }
            }
            if (args.series.index === 1) {
                if (args.chart.series[2].visible) {
                    args.chart.series[2].cornerRadius.topLeft = 4;
                    args.chart.series[2].cornerRadius.topRight = 4;
                    args.chart.series[1].cornerRadius.topLeft = 0;
                    args.chart.series[1].cornerRadius.topRight = 0;
                } else if (args.series.visible && args.chart.series[0].visible) {
                    args.chart.series[0].cornerRadius.topLeft = 4;
                    args.chart.series[0].cornerRadius.topRight = 4;
                    args.chart.series[1].cornerRadius.topLeft = 0;
                    args.chart.series[1].cornerRadius.topRight = 0;
                } else {
                    args.chart.series[1].cornerRadius.topLeft = 4;
                    args.chart.series[1].cornerRadius.topRight = 4;
                    args.chart.series[0].cornerRadius.topLeft = 0;
                    args.chart.series[0].cornerRadius.topRight = 0;
                }
            }

            if (args.series.index === 2) {
                if (!args.series.visible) {
                    args.chart.series[2].cornerRadius.topLeft = 4;
                    args.chart.series[2].cornerRadius.topRight = 4;
                    args.chart.series[1].cornerRadius.topLeft = 0;
                    args.chart.series[1].cornerRadius.topRight = 0;
                    args.chart.series[0].cornerRadius.topLeft = 0;
                    args.chart.series[0].cornerRadius.topRight = 0;
                } else if (args.chart.series[1].visible) {
                    args.chart.series[1].cornerRadius.topLeft = 4;
                    args.chart.series[1].cornerRadius.topRight = 4;
                    args.chart.series[2].cornerRadius.topLeft = 0;
                    args.chart.series[2].cornerRadius.topRight = 0;
                } else if (args.series.visible && args.chart.series[0].visible) {
                    args.chart.series[0].cornerRadius.topLeft = 4;
                    args.chart.series[0].cornerRadius.topRight = 4;
                    args.chart.series[2].cornerRadius.topLeft = 0;
                    args.chart.series[2].cornerRadius.topRight = 0;
                }
            }
        }
        var axisLabelRender = function (args) {
            {
                args.text = args.text.replace("0000000", "0M").replace("000000", "M");
            }
        }
    </script>
}

```

### src/components/chart-stacked-column/ChartController.cs

```cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Charts;

namespace EJ2MVCSampleBrowser.Controllers.Chart
{
    public partial class ChartController : Controller
    {
        // GET: StackedColumn
        public ActionResult StackedColumn()
        {
            List<StackedColumnChartData> ChartPoints = new List<StackedColumnChartData>
            {
                new StackedColumnChartData { X = "2019", Y = 28.5 },
                new StackedColumnChartData { X = "2020", Y = 27.5 },
            };
            List<StackedColumnChartData> ChartPoints1 = new List<StackedColumnChartData>
            {
                new StackedColumnChartData { X = "2019", Y = 26.9 },
                new StackedColumnChartData { X = "2020", Y = 29.3 },
            };
            List<StackedColumnChartData> ChartPoints2 = new List<StackedColumnChartData>
            {
                new StackedColumnChartData { X = "2019", Y = 19.9 },
                new StackedColumnChartData { X = "2020", Y = 14.6 },
            };
            bool isMobile = Request.Browser.IsMobileDevice;
            if (isMobile)
            {
                ChartPoints.RemoveRange(0, 2);
                ChartPoints1.RemoveRange(0, 2);
                ChartPoints2.RemoveRange(0, 2);

            };

            ViewData["ChartPoints"] = ChartPoints;
            ViewData["ChartPoints1"] = ChartPoints1;
            ViewData["ChartPoints2"] = ChartPoints2;
            return View("~/Views/Home/chart/stacked-column/Chart.cshtml");
        }
        public class StackedColumnChartData
        {
            public string X;
            public double Y;
        }
    }
}
```
