How can I help you?
Area in Blazor Charts Component
4 Feb 202619 minutes to read
Area
The Area Chart visualizes time-dependent data, highlighting trends at regular intervals by filling the area beneath a line connecting data points. To create an area series, set the series Type property to Area. Area charts are effective for illustrating changes over time or categories, as the filled area accentuates the magnitude of values. Supported axis ValueType options include Category, DateTime, DateTimeCategory, Double and Logarithmic.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis Minimum="1900" Maximum="2000" EdgeLabelPlacement="EdgeLabelPlacement.Shift"/>
<ChartSeriesCollection>
<ChartSeries DataSource="@SalesDetails" XName="X" YName="Y" Type="ChartSeriesType.Area">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public double X { get; set; }
public double Y { get; set; }
}
public List<ChartData> SalesDetails = new List<ChartData>
{
new ChartData { X= 1900, Y= 4 },
new ChartData { X= 1920, Y= 3.0 },
new ChartData { X= 1940, Y= 3.8 },
new ChartData { X= 1960, Y= 3.4 },
new ChartData { X= 2000, Y= 3.9 }
};
}
NOTE
Refer to the Blazor Area Charts feature page for more details and explore the Blazor Area Chart Example to see usage for time-dependent data and trend visualization.
Binding data with series
You can bind data to the chart using the DataSource property within the series configuration. The DataSource value can be set using either SfDataManager property values or a list of business objects. More information on data binding can be found here. To display the data correctly, map the fields from the data to the chart series’ XName and YName properties.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis Minimum="1900" Maximum="2000" EdgeLabelPlacement="EdgeLabelPlacement.Shift"/>
<ChartSeriesCollection>
<ChartSeries DataSource="@SalesDetails" XName="X" YName="Y" Type="ChartSeriesType.Area">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public double X { get; set; }
public double Y { get; set; }
}
public List<ChartData> SalesDetails = new List<ChartData>
{
new ChartData { X= 1900, Y= 4 },
new ChartData { X= 1920, Y= 3.0 },
new ChartData { X= 1940, Y= 3.8 },
new ChartData { X= 1960, Y= 3.4 },
new ChartData { X= 2000, Y= 3.9 }
};
}Series customization
The following properties can be used to customize the Area series.
Fill
The Fill property specifies the color applied to the series.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis Minimum="1900" Maximum="2000" EdgeLabelPlacement="EdgeLabelPlacement.Shift"/>
<ChartSeriesCollection>
<ChartSeries DataSource="@SalesDetails" Fill="blue" XName="X" YName="Y" Type="ChartSeriesType.Area">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public double X { get; set; }
public double Y { get; set; }
}
public List<ChartData> SalesDetails = new List<ChartData>
{
new ChartData { X= 1900, Y= 4 },
new ChartData { X= 1920, Y= 3.0 },
new ChartData { X= 1940, Y= 3.8 },
new ChartData { X= 1960, Y= 3.4 },
new ChartData { X= 2000, Y= 3.9 }
};
}The Fill property can be used to apply a gradient color to the area series. By configuring this property with gradient values will create a visually appealing effect in which the color transitions smoothly from one shade to another.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis Minimum="1900" Maximum="2000" EdgeLabelPlacement="EdgeLabelPlacement.Shift"/>
<ChartSeriesCollection>
<ChartSeries DataSource="@SalesDetails" Fill="url(#grad1)" XName="X" YName="Y" Type="ChartSeriesType.Area">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
<svg style="height: 0">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="20%" style="stop-color:orange;stop-opacity:1" />
<stop offset="100%" style="stop-color:black;stop-opacity:1" />
</linearGradient>
</defs>
</svg>
@code {
public class ChartData
{
public double X { get; set; }
public double Y { get; set; }
}
public List<ChartData> SalesDetails = new List<ChartData>
{
new ChartData { X= 1900, Y= 4 },
new ChartData { X= 1920, Y= 3.0 },
new ChartData { X= 1940, Y= 3.8 },
new ChartData { X= 1960, Y= 3.4 },
new ChartData { X= 2000, Y= 3.9 }
};
}Opacity
The Opacity property determines the area Fill transparency for the area series.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis Minimum="1900" Maximum="2000" EdgeLabelPlacement="EdgeLabelPlacement.Shift"/>
<ChartSeriesCollection>
<ChartSeries DataSource="@SalesDetails" Opacity="0.3" XName="X" YName="Y" Type="ChartSeriesType.Area">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public double X { get; set; }
public double Y { get; set; }
}
public List<ChartData> SalesDetails = new List<ChartData>
{
new ChartData { X= 1900, Y= 4 },
new ChartData { X= 1920, Y= 3.0 },
new ChartData { X= 1940, Y= 3.8 },
new ChartData { X= 1960, Y= 3.4 },
new ChartData { X= 2000, Y= 3.9 }
};
}DashArray
The DashArray property specifies the pattern of dashes and gaps in the series border.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis Minimum="1900" Maximum="2000" EdgeLabelPlacement="EdgeLabelPlacement.Shift"/>
<ChartSeriesCollection>
<ChartSeries DataSource="@SalesDetails" DashArray="5,5" XName="X" YName="Y" Type="ChartSeriesType.Area">
<ChartSeriesBorder Width="2" Color="red"></ChartSeriesBorder>
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public double X { get; set; }
public double Y { get; set; }
}
public List<ChartData> SalesDetails = new List<ChartData>
{
new ChartData { X= 1900, Y= 4 },
new ChartData { X= 1920, Y= 3.0 },
new ChartData { X= 1940, Y= 3.8 },
new ChartData { X= 1960, Y= 3.4 },
new ChartData { X= 2000, Y= 3.9 }
};
}Area Border
The following properties in the ChartSeriesBorder can be used to customize the border of the Area Chart.
- Width - Specifies the width for the border of the Area Chart.
- Color - Specifies the Color for the border of the Area Chart.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis Minimum="1900" Maximum="2000" EdgeLabelPlacement="EdgeLabelPlacement.Shift"/>
<ChartSeriesCollection>
<ChartSeries DataSource="@SalesDetails" XName="X" YName="Y" Type="ChartSeriesType.Area">
<ChartSeriesBorder Width="2" Color="#962D18"></ChartSeriesBorder>
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public double X { get; set; }
public double Y { get; set; }
}
public List<ChartData> SalesDetails = new List<ChartData>
{
new ChartData { X= 1900, Y= 4 },
new ChartData { X= 1920, Y= 3.0 },
new ChartData { X= 1940, Y= 3.8 },
new ChartData { X= 1960, Y= 3.4 },
new ChartData { X= 2000, Y= 3.9 }
};
}Multicolored area
To render a multicolored area series in a chart, a few configuration steps must be followed to ensure it is set up correctly. Below is a concise guide outlining the process.
-
Set the series type: Define the series
TypeasMultiColoredAreain chart series 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
ChartSegmentproperty. Each segment can be customized with properties such asValue,Color, andDashArray.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartSeriesCollection>
<ChartSeries DataSource="@WeatherReports" XName="X" YName="Y" Type="Syncfusion.Blazor.Charts.ChartSeriesType.MultiColoredArea">
<ChartSegments>
<ChartSegment Value="2007" Color="blue" />
<ChartSegment Value="2009" Color="red" />
<ChartSegment Color="green"></ChartSegment>
</ChartSegments>
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public double X { get; set; }
public double Y { get; set; }
}
public List<ChartData> WeatherReports = 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 }
};
}Empty points
Data points with null, double.NaN 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.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis Minimum="1900" Maximum="2000" EdgeLabelPlacement="EdgeLabelPlacement.Shift" />
<ChartSeriesCollection>
<ChartSeries DataSource="@SalesDetails" XName="X" YName="Y" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Area">
<ChartEmptyPointSettings Mode="EmptyPointMode.Zero"></ChartEmptyPointSettings>
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public double X { get; set; }
public double Y { get; set; }
}
public List<ChartData> SalesDetails = new List<ChartData>
{
new ChartData { X= 1900, Y= 4 },
new ChartData { X= 1920, Y= 3.0 },
new ChartData { X= 1940, Y= double.NaN },
new ChartData { X= 1960, Y= 3.4 },
new ChartData { X= 2000, Y= 3.9 }
};
}Fill
Use the Fill property to specify the fill color for empty points in the series.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis Minimum="1900" Maximum="2000" EdgeLabelPlacement="EdgeLabelPlacement.Shift" />
<ChartSeriesCollection>
<ChartSeries DataSource="@SalesDetails" XName="X" YName="Y" Type="ChartSeriesType.Area">
<ChartEmptyPointSettings Fill="red" Mode="EmptyPointMode.Zero" />
<ChartMarker Visible="true" Height="7" Width="7" IsFilled="true"></ChartMarker>
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public double X { get; set; }
public double Y { get; set; }
}
public List<ChartData> SalesDetails = new List<ChartData>
{
new ChartData { X= 1900, Y= 4 },
new ChartData { X= 1920, Y= 3.0 },
new ChartData { X= 1940, Y= double.NaN },
new ChartData { X= 1960, Y= 3.4 },
new ChartData { X= 2000, Y= 3.9 }
};
}Border
Use the Border property to customize the Width and Color of the border for empty points.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis Minimum="1900" Maximum="2000" EdgeLabelPlacement="EdgeLabelPlacement.Shift" />
<ChartSeriesCollection>
<ChartSeries DataSource="@SalesDetails" XName="X" YName="Y" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Area">
<ChartEmptyPointSettings Fill="red" Mode="EmptyPointMode.Zero">
<ChartEmptyPointBorder Color="green" Width="2"></ChartEmptyPointBorder>
</ChartEmptyPointSettings>
<ChartMarker Visible="true" Height="7" Width="7" IsFilled="true"></ChartMarker>
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public double X { get; set; }
public double Y { get; set; }
}
public List<ChartData> SalesDetails = new List<ChartData>
{
new ChartData { X= 1900, Y= 4 },
new ChartData { X= 1920, Y= 3.0 },
new ChartData { X= 1940, Y= double.NaN },
new ChartData { X= 1960, Y= 3.4 },
new ChartData { X= 2000, Y= 3.9 }
};
}Events
Series render
The OnSeriesRender event allows you to customize series properties, such as Data, Fill, and Series, before rendering the chart.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis Minimum="1900" Maximum="2000" EdgeLabelPlacement="EdgeLabelPlacement.Shift"/>
<ChartEvents OnSeriesRender="SeriesRender"></ChartEvents>
<ChartSeriesCollection>
<ChartSeries DataSource="@SalesDetails" XName="X" YName="Y" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Area" />
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public double X { get; set; }
public double Y { get; set; }
}
public void SeriesRender(SeriesRenderEventArgs args)
{
args.Fill = "#FF4081";
}
public List<ChartData> SalesDetails = new List<ChartData>
{
new ChartData { X= 1900, Y= 4 },
new ChartData { X= 1920, Y= 3.0 },
new ChartData { X= 1940, Y= 3.8 },
new ChartData { X= 1960, Y= 3.4 },
new ChartData { X= 2000, Y= 3.9 }
};
}Point render
The OnPointRender event allows for customization of data points before they render on the chart.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis Minimum="1900" Maximum="2000" EdgeLabelPlacement="EdgeLabelPlacement.Shift"/>
<ChartEvents OnPointRender="PointRender"></ChartEvents>
<ChartSeriesCollection>
<ChartSeries DataSource="@SalesDetails" XName="X" YName="Y" Type="ChartSeriesType.Area">
<ChartMarker Visible="true" Width="7" Height="7"></ChartMarker>
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public double X { get; set; }
public double Y { get; set; }
}
public void PointRender(PointRenderEventArgs args)
{
args.Fill = (args.Point.Index % 2 != 0) ? "#ff6347" : "#009cb8";
}
public List<ChartData> SalesDetails = new List<ChartData>
{
new ChartData { X= 1900, Y= 4 },
new ChartData { X= 1920, Y= 3.0 },
new ChartData { X= 1940, Y= 3.8 },
new ChartData { X= 1960, Y= 3.4 },
new ChartData { X= 2000, Y= 3.9 }
};
}NOTE
Refer to the Blazor Charts feature tour page for its groundbreaking feature representations and also explore the Blazor Chart Example to know various chart types and how to represent time-dependent data, showing trends at equal intervals.