Area in ASP.NET MVC Charts Component

30 Sep 202424 minutes to read

Area

To render an area series in your chart, you need to follow a few steps to configure it correctly. Here’s a concise guide on how to do this:

  • Set the series type: Define the series Type as Area in your chart configuration. This indicates that the data should be represented as an area chart, which is ideal for showing trends over time or across categories, with filled areas beneath the lines representing data points.
@Html.EJS().Chart("container").Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Area).
      XName("x").
      YName("y").
      DataSource(ViewBag.dataSource).
      Name("Gold").
      Add();
   }).PrimaryXAxis(px =>
         px.Interval(1)
            .ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
            .IsIndexed(true)
   ).Title("Olympic Medal Counts - RIO").Render()
public ActionResult Index()
        {
            List<AxisLabelData> chartData = new List<AxisLabelData>
            {
                new AxisLabelData { x= "South Korea", y= 39.4, color="red" },
                new AxisLabelData { x= "India", y= 61.3, color="green" }, 
                new AxisLabelData { x= "Pakistan", y= 20.4, color="#ff0097" },
                new AxisLabelData { x= "Germany", y= 65.1, color="crimson" }, 
                new AxisLabelData { x= "Australia", y= 15.8, color="blue" },
                new AxisLabelData { x= "Italy", y= 29.2, color="darkorange" },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class AxisLabelData
        {
            public string x;
            public double y;
            public string color;
        }

Binding data with series

You can bind data to the chart using the DataSource property within the series configuration. This allows you to connect a JSON dataset or remote data to your chart. To display the data correctly, map the fields from the data to the chart series XName and YName properties.

@Html.EJS().Chart("container").Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Area).
      XName("x").
      YName("y").
      DataSource(ViewBag.dataSource).
      Name("Gold").
      Add();
   }).PrimaryXAxis(px =>
         px.Interval(1)
            .ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
            .IsIndexed(true)
   ).Title("Olympic Medal Counts - RIO").Render()
public ActionResult Index()
        {
            List<AxisLabelData> chartData = new List<AxisLabelData>
            {
                new AxisLabelData { x= "South Korea", y= 39.4, color="red" },
                new AxisLabelData { x= "India", y= 61.3, color="green" }, 
                new AxisLabelData { x= "Pakistan", y= 20.4, color="#ff0097" },
                new AxisLabelData { x= "Germany", y= 65.1, color="crimson" }, 
                new AxisLabelData { x= "Australia", y= 15.8, color="blue" },
                new AxisLabelData { x= "Italy", y= 29.2, color="darkorange" },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class AxisLabelData
        {
            public string x;
            public double y;
            public string color;
        }

Series customization

The following properties can be used to customize the area series.

Fill

The Fill property determines the color applied to the series.

@Html.EJS().Chart("container").Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Area).
      XName("x").
      YName("y").
      DataSource(ViewBag.dataSource).
      Fill("#69D2E7").
      Add();
   }).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Title("Olympic Medals").Render()
public ActionResult Index()
        {
            List<AxisLabelData> chartData = new List<AxisLabelData>
            {
                new AxisLabelData { x= "South Korea", y= 39.4 },
                new AxisLabelData { x= "India", y= 61.3 }, 
                new AxisLabelData { x= "Pakistan", y= 20.4 },
                new AxisLabelData { x= "Germany", y= 65.1 }, 
                new AxisLabelData { x= "Australia", y= 15.8 },
                new AxisLabelData { x= "Italy", y= 29.2 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class AxisLabelData
        {
            public string x;
            public double y;
        }

The Fill property can be used to apply a gradient color to the area series. By configuring this property with gradient values, you can create a visually appealing effect in which the color transitions smoothly from one shade to another.

<svg style="width:1px; height:1px">
    <defs>
        <linearGradient id="gradient">
            <stop offset="0%" style="stop-color:blue;stop-opacity:5" />
            <stop offset="50%" style="stop-color:violet;stop-opacity:5" />
        </linearGradient>
    </defs>
</svg>

@Html.EJS().Chart("container").Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Area).
      XName("x").
      YName("y").
      DataSource(ViewBag.dataSource).
      Fill("url(#gradient)").
      Add();
   }).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Title("Olympic Medals").Render()
public ActionResult Index()
        {
            List<AxisLabelData> chartData = new List<AxisLabelData>
            {
                new AxisLabelData { x= "South Korea", y= 39.4 },
                new AxisLabelData { x= "India", y= 61.3 }, 
                new AxisLabelData { x= "Pakistan", y= 20.4 },
                new AxisLabelData { x= "Germany", y= 65.1 }, 
                new AxisLabelData { x= "Australia", y= 15.8 },
                new AxisLabelData { x= "Italy", y= 29.2 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class AxisLabelData
        {
            public string x;
            public double y;
        }

Opacity

The Opacity property specifies the transparency level of the fill. Adjusting this property allows you to control how opaque or transparent the fill color of the series appears.

@Html.EJS().Chart("container").Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Area).
      XName("x").
      YName("y").
      DataSource(ViewBag.dataSource).
      Name("Gold").
      Opacity(0.5).
      Add();
   }).PrimaryXAxis(px =>
         px.Interval(1)
            .ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
            .IsIndexed(true)
   ).Title("Olympic Medal Counts - RIO").Render()
public ActionResult Index()
        {
            List<AxisLabelData> chartData = new List<AxisLabelData>
            {
                new AxisLabelData { x= "South Korea", y= 39.4, color="red" },
                new AxisLabelData { x= "India", y= 61.3, color="green" }, 
                new AxisLabelData { x= "Pakistan", y= 20.4, color="#ff0097" },
                new AxisLabelData { x= "Germany", y= 65.1, color="crimson" }, 
                new AxisLabelData { x= "Australia", y= 15.8, color="blue" },
                new AxisLabelData { x= "Italy", y= 29.2, color="darkorange" },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class AxisLabelData
        {
            public string x;
            public double y;
            public string color;
        }

Dash array

The DashArray property determines the pattern of dashes and gaps in the series.

@Html.EJS().Chart("container").Series(series =>
{
    series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Area).
    XName("x").
    YName("y").
    DataSource(ViewBag.dataSource).
    Name("Gold").
    DashArray("5,5").
    Border(ViewBag.seriesBorder).
    Add();
}).PrimaryXAxis(px =>
      px.Interval(1)
         .ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
         .IsIndexed(true)
   ).Title("Olympic Medal Counts - RIO").Render()
public ActionResult Index()
        {
            List<AxisLabelData> chartData = new List<AxisLabelData>
            {
                new AxisLabelData { x= "South Korea", y= 39.4, color="red" },
                new AxisLabelData { x= "India", y= 61.3, color="green" }, 
                new AxisLabelData { x= "Pakistan", y= 20.4, color="#ff0097" },
                new AxisLabelData { x= "Germany", y= 65.1, color="crimson" }, 
                new AxisLabelData { x= "Australia", y= 15.8, color="blue" },
                new AxisLabelData { x= "Italy", y= 29.2, color="darkorange" },
            };
            ViewBag.dataSource = chartData;
            ChartBorder border = new ChartBorder();
            border.Width = 2;
            border.Color = "red";
            ViewBag.seriesBorder = border;
            return View();
        }
        public class AxisLabelData
        {
            public string x;
            public double y;
            public string color;
        }

Area border

Use the Border property to customize the width and color of the series border.

@Html.EJS().Chart("container").Series(series =>
{
    series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Area).
    XName("x").
    YName("y").
    DataSource(ViewBag.dataSource).
    Name("Gold").
    Fill("#69D2E7").
    Border(ViewBag.seriesBorder).
    Add();
}).PrimaryXAxis(px =>
      px.Interval(1)
         .ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
         .IsIndexed(true)
   ).Title("Olympic Medal Counts - RIO").Render()
public ActionResult Index()
        {
            List<AxisLabelData> chartData = new List<AxisLabelData>
            {
                new AxisLabelData { x= "South Korea", y= 39.4, color="red" },
                new AxisLabelData { x= "India", y= 61.3, color="green" }, 
                new AxisLabelData { x= "Pakistan", y= 20.4, color="#ff0097" },
                new AxisLabelData { x= "Germany", y= 65.1, color="crimson" }, 
                new AxisLabelData { x= "Australia", y= 15.8, color="blue" },
                new AxisLabelData { x= "Italy", y= 29.2, color="darkorange" },
            };
            ViewBag.dataSource = chartData;
            ChartBorder border = new ChartBorder();
            border.Width = 2;
            border.Color = "#962D18";
            ViewBag.seriesBorder = border;
            return View();
        }
        public class AxisLabelData
        {
            public string x;
            public double y;
            public string color;
        }

Multicolored area

To render a multicolored area series in your chart, you need to follow a few steps to configure it correctly. Here’s a concise guide on how to do this:

  • Set the series type: Define the series Type as MultiColoredArea in your chart configuration. This specifies that the series should be rendered as a multicolored area chart, with different segments of the area having distinct colors.

  • Customize the Segments: Define the segments of the series using the segments property. Each segment can be customized with properties such as value, color, and dashArray.

    • Value - Specifies the endpoint of the segment.
    • Color - Defines the color of the segment.
    • DashArray - Defines the dashes or gaps in the segment.
@Html.EJS().Chart("container").Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Area).  
      XName("x").
      YName("y").
      PointColorMapping("Color").
      DataSource(ViewBag.dataSource).
      Name("Gold").
      Add();
   })
   .PrimaryXAxis(px => 
         px.Interval(1)
            .ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
            .IsIndexed(true)
   )
   .Title("Olympic Medal Counts - RIO").Render()
public IActionResult Index()
        {
            List<ChartData> chartData = new List<ChartData>
            {
               new ChartData{ x= 2005, y= 28 },
               new ChartData{ x= 2006, y= 25},
               new ChartData{ x= 2007, y= 26 },
               new ChartData{ x= 2008, y= 27 },
               new ChartData{ x= 2009, y= 32}, 
               new ChartData{ x= 2010, y= 35 }, 
               new ChartData{ x= 2011, y= 25 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ChartData
        {
            public double x;
            public double y;
        }

Empty points

Data points with null or undefined values are considered empty. Empty data points are ignored and not plotted on the chart.

Mode

Use the Mode property to define how empty or missing data points are handled in the series. The default mode for empty points is Gap.

@Html.EJS().Chart("container").Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Area).
      XName("month").
      YName("sales").
      DataSource(ViewBag.dataSource).
      Name("Gold").EmptyPointSettings(ViewBag.emptyPoint).
      Add();
   }).PrimaryXAxis(px =>
      px.Interval(1)
         .ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
         .IsIndexed(true)
   ).Title("Olympic Medal Counts - RIO").Render()
public ActionResult Index()
{
    List<AxisLabelData> chartData = new List<AxisLabelData>
        {
            new AxisLabelData { month = "Jan", sales = 35 },
            new AxisLabelData { month = "Feb", sales = 28 },
            new AxisLabelData { month = "Mar", sales = 34 },
            new AxisLabelData { month = "Apr", sales = null },
            new AxisLabelData { month = "May", sales = 40 },
            new AxisLabelData { month = "Jun", sales = 32 },
            new AxisLabelData { month = "Jul", sales = 35 },
            new AxisLabelData { month = "Aug" },
            new AxisLabelData { month = "Sep", sales = 38 },
            new AxisLabelData { month = "Oct", sales = 30 },
            new AxisLabelData { month = "Nov", sales = 25 },
            new AxisLabelData { month = "Dec", sales = 32 },
        };
        ViewBag.dataSource = chartData;
        ChartEmptyPointSettings chartEmptyPointSettings = new ChartEmptyPointSettings();
        chartEmptyPointSettings.Mode = EmptyPointMode.Zero;
        ViewBag.emptyPoint = chartEmptyPointSettings;
        return View();
}


public class AxisLabelData
{
    public string month;
    public double? sales;
}

Fill

Use the Fill property to customize the fill color of empty points in the series.

@Html.EJS().Chart("container").Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Spline).
      XName("month").
      YName("sales").
      DataSource(ViewBag.dataSource).
      Name("Gold").EmptyPointSettings(ViewBag.emptyPoint).
      Marker(ViewBag.marker).
      Add();
   }).PrimaryXAxis(px =>
      px.Interval(1)
         .ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
         .IsIndexed(true)
   ).Title("Olympic Medal Counts - RIO").Render()
public ActionResult Index()
{
    List<AxisLabelData> chartData = new List<AxisLabelData>
        {
            new AxisLabelData { month = "Jan", sales = 35 },
            new AxisLabelData { month = "Feb", sales = 28 },
            new AxisLabelData { month = "Mar", sales = 34 },
            new AxisLabelData { month = "Apr", sales = null },
            new AxisLabelData { month = "May", sales = 40 },
            new AxisLabelData { month = "Jun", sales = 32 },
            new AxisLabelData { month = "Jul", sales = 35 },
            new AxisLabelData { month = "Aug" },
            new AxisLabelData { month = "Sep", sales = 38 },
            new AxisLabelData { month = "Oct", sales = 30 },
            new AxisLabelData { month = "Nov", sales = 25 },
            new AxisLabelData { month = "Dec", sales = 32 },
        };
        ViewBag.dataSource = chartData;
        ChartEmptyPointSettings chartEmptyPointSettings = new ChartEmptyPointSettings();
        chartEmptyPointSettings.Mode = EmptyPointMode.Average;
        chartEmptyPointSettings.Fill = "red";
        ViewBag.emptyPoint = chartEmptyPointSettings;
        ChartMarkerSettings marker = new ChartMarkerSettings();
        marker.Visible = true;
        marker.Width = 7;
        marker.Height = 7;
        marker.IsFilled = true;
        ViewBag.marker = marker;
        return View();
}


public class AxisLabelData
{
    public string month;
    public double? sales;
}

Border

Use the Border property to customize the width and color of the border for empty points.

@Html.EJS().Chart("container").Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Area).
      XName("month").
      YName("sales").
      DataSource(ViewBag.dataSource).
      Name("Gold").EmptyPointSettings(ViewBag.emptyPoint).
      Marker(ViewBag.marker).
      Add();
   }).PrimaryXAxis(px =>
      px.Interval(1)
         .ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
         .IsIndexed(true)
   ).Title("Olympic Medal Counts - RIO").Render()
public ActionResult Index()
{
    List<AxisLabelData> chartData = new List<AxisLabelData>
        {
            new AxisLabelData { month = "Jan", sales = 35 },
            new AxisLabelData { month = "Feb", sales = 28 },
            new AxisLabelData { month = "Mar", sales = 34 },
            new AxisLabelData { month = "Apr", sales = null },
            new AxisLabelData { month = "May", sales = 40 },
            new AxisLabelData { month = "Jun", sales = 32 },
            new AxisLabelData { month = "Jul", sales = 35 },
            new AxisLabelData { month = "Aug" },
            new AxisLabelData { month = "Sep", sales = 38 },
            new AxisLabelData { month = "Oct", sales = 30 },
            new AxisLabelData { month = "Nov", sales = 25 },
            new AxisLabelData { month = "Dec", sales = 32 },
        };
        ViewBag.dataSource = chartData;
        ChartEmptyPointSettings chartEmptyPointSettings = new ChartEmptyPointSettings();
        chartEmptyPointSettings.Mode = EmptyPointMode.Zero;
        chartEmptyPointSettings.Fill = "red";
        chartEmptyPointSettings.Border.Width = 2;
        chartEmptyPointSettings.Border.Color = "green";
        ViewBag.emptyPoint = chartEmptyPointSettings;
        ChartMarkerSettings marker = new ChartMarkerSettings();
        marker.Visible = true;
        marker.Width = 7;
        marker.Height = 7;
        marker.IsFilled = true;
        ViewBag.marker = marker;
        return View();
}


public class AxisLabelData
{
    public string month;
    public double? sales;
}

Events

Series render

The SeriesRender event allows you to customize series properties, such as data, fill, and name, before they are rendered on the chart.

@Html.EJS().Chart("container").SeriesRender("changeColor").Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Area).
      XName("month").
      YName("sales").
      DataSource(ViewBag.dataSource).
      Name("Gold").
      Add();
   }).PrimaryXAxis(px =>
      px.Interval(1)
         .ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
         .IsIndexed(true)
   ).Title("Olympic Medal Counts - RIO").Render()

<script>
    function changeColor(args) {
        args.fill = '#ff6347';
    }
</script>
public ActionResult Index()
{
    List<AxisLabelData> chartData = new List<AxisLabelData>
    {
        new AxisLabelData { month = "Jan", sales = 35 },
        new AxisLabelData { month = "Feb", sales = 28 },
        new AxisLabelData { month = "Mar", sales = 34 },
        new AxisLabelData { month = "Apr", sales = 30 },
        new AxisLabelData { month = "May", sales = 40 },
        new AxisLabelData { month = "Jun", sales = 32 },
        new AxisLabelData { month = "Jul", sales = 35 },
        new AxisLabelData { month = "Aug", sales = 43 },
        new AxisLabelData { month = "Sep", sales = 38 },
        new AxisLabelData { month = "Oct", sales = 30 },
        new AxisLabelData { month = "Nov", sales = 25 },
        new AxisLabelData { month = "Dec", sales = 32 },
    };
    ViewBag.dataSource = chartData;
    return View();
}
public class AxisLabelData
{
    public string month;
    public double? sales;
}

Point render

The PointRender event allows you to customize each data point before it is rendered on the chart.

@Html.EJS().Chart("container").PointRender("changeColor").Series(series =>
   {
      series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Area).
      XName("month").
      YName("sales").
      DataSource(ViewBag.dataSource).
      Name("Gold").Width(2).
      Marker(ViewBag.marker).
      Add();
   }).PrimaryXAxis(px =>
      px.Interval(1)
         .ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
         .IsIndexed(true)
   ).Title("Olympic Medal Counts - RIO").Render()

<script>
    function changeColor(args) {
        if (args.point.index % 2 !== 0) {
            args.fill = '#ff6347';
        }
        else {
            args.fill = '#009cb8';
        }
    }
</script>
public ActionResult Index()
{
    List<AxisLabelData> chartData = new List<AxisLabelData>
    {
        new AxisLabelData { month = "Jan", sales = 35 },
        new AxisLabelData { month = "Feb", sales = 28 },
        new AxisLabelData { month = "Mar", sales = 34 },
        new AxisLabelData { month = "Apr", sales = 30 },
        new AxisLabelData { month = "May", sales = 40 },
        new AxisLabelData { month = "Jun", sales = 32 },
        new AxisLabelData { month = "Jul", sales = 35 },
        new AxisLabelData { month = "Aug", sales = 43 },
        new AxisLabelData { month = "Sep", sales = 38 },
        new AxisLabelData { month = "Oct", sales = 30 },
        new AxisLabelData { month = "Nov", sales = 25 },
        new AxisLabelData { month = "Dec", sales = 32 },
    };
    ViewBag.dataSource = chartData;
    ChartMarkerSettings chartMarkerSettings = new ChartMarkerSettings();
    chartMarkerSettings.Visible = true;
    chartMarkerSettings.IsFilled = true;
    chartMarkerSettings.Height = 7;
    chartMarkerSettings.Width = 7;
    ViewBag.marker = chartMarkerSettings;
    return View();
}
public class AxisLabelData
{
    public string month;
    public double? sales;
}

See Also