Spline Range Area in ASP.NET MVC Charts Component
12 Nov 202424 minutes to read
Spline Range Area
To render a spline range 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 SplineRangeArea in your chart configuration. This indicates that the data should be represented as a spline range area chart, which is ideal for visualizing continuous data points as a set of splines that vary between high and low values over intervals of time and across different categories. -
Provide high and low values: The SplineRangeArea series requires two y-values for each data point, you need to specify both the high and low values. The high value represents the maximum range, while the low value represents the minimum range for each data point. These values define the upper and lower boundaries of the area for each point on the chart.
@Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.SplineRangeArea).
XName("x").
High("high").
Low("low").
DataSource(ViewBag.dataSource).
Name("England").
Add();
}).PrimaryXAxis(px =>
px.MajorGridLines(mg => mg.Width(0))
.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).PrimaryYAxis(py =>
py.LabelFormat("{value}˚C")
.Minimum(0)
.Maximum(40)
.MajorTickLines(mt => mt.Width(0))
.LineStyle(ls => ls.Width(0))
).Render()
public IActionResult Index () {
List<ChartData> chartData = new List<ChartData>
{
new ChartData { x = "Jan", high = 14, low = 4, high1 = 29, low1 = 19 },
new ChartData { x = "Feb", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Mar", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Apr", high = 22, low = 12, high1 = 37, low1 = 27 },
new ChartData { x = "May", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Jun", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Jul", high = 15, low = 5, high1 = 30, low1 = 20 },
new ChartData { x = "Aug", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Sep", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Oct", high = 22, low = 12, high1 = 37, low1 = 27 },
new ChartData { x = "Nov", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Dec", high = 17, low = 7, high1 = 32, low1 = 22 }
};
ViewBag.dataSource = chartData;
return View();
}
public class ChartData
{
public string x;
public double high;
public double low;
public double high1;
public double low1;
}
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
, High
, and Low
properties.
@Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.SplineRangeArea).
XName("x").
High("high").
Low("low").
DataSource(ViewBag.dataSource).
Name("England").
Add();
}).PrimaryXAxis(px =>
px.MajorGridLines(mg => mg.Width(0))
.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).PrimaryYAxis(py =>
py.LabelFormat("{value}˚C")
.Minimum(0)
.Maximum(40)
.MajorTickLines(mt => mt.Width(0))
.LineStyle(ls => ls.Width(0))
).Render()
public IActionResult Index () {
List<ChartData> chartData = new List<ChartData>
{
new ChartData { x = "Jan", high = 14, low = 4, high1 = 29, low1 = 19 },
new ChartData { x = "Feb", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Mar", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Apr", high = 22, low = 12, high1 = 37, low1 = 27 },
new ChartData { x = "May", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Jun", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Jul", high = 15, low = 5, high1 = 30, low1 = 20 },
new ChartData { x = "Aug", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Sep", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Oct", high = 22, low = 12, high1 = 37, low1 = 27 },
new ChartData { x = "Nov", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Dec", high = 17, low = 7, high1 = 32, low1 = 22 }
};
ViewBag.dataSource = chartData;
return View();
}
public class ChartData
{
public string x;
public double high;
public double low;
public double high1;
public double low1;
}
Series customization
The following properties can be used to customize the spline range 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.SplineRangeArea).
XName("x").
High("high").
Low("low").
DataSource(ViewBag.dataSource).
Fill("blue").
Name("India").
Add();
}).PrimaryXAxis(px =>
px.MajorGridLines(mg => mg.Width(0))
.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).PrimaryYAxis(py => py.LabelFormat("{value}˚C")
.Minimum(0)
.Maximum(40)
.MajorTickLines(mt => mt.Width(0))
.LineStyle(ls => ls.Width(0))
).Title("Monthly Temperature Range").Render()
public IActionResult Index ()
{
List<ChartData> chartData = new List<ChartData>
{
new ChartData { x = "Jan", high = 14, low = 4, high1 = 29, low1 = 19 },
new ChartData { x = "Feb", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Mar", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Apr", high = 22, low = 12, high1 = 37, low1 = 27 },
new ChartData { x = "May", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Jun", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Jul", high = 15, low = 5, high1 = 30, low1 = 20 },
new ChartData { x = "Aug", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Sep", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Oct", high = 22, low = 12, high1 = 37, low1 = 27 },
new ChartData { x = "Nov", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Dec", high = 17, low = 7, high1 = 32, low1 = 22 }
};
ViewBag.dataSource = chartData;
return View();
}
public class ChartData
{
public string x;
public double high;
public double low;
public double high1;
public double low1;
}
The Fill
property can be used to apply a gradient color to the spline range 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:coral;stop-opacity:5" />
<stop offset="50%" style="stop-color:mediumseagreen;stop-opacity:5" />
</linearGradient>
</defs>
</svg>
@Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.SplineRangeArea).
XName("x").
High("high").
Low("low").
DataSource(ViewBag.dataSource).
Fill("url(#gradient)").
Name("India").
Add();
}).PrimaryXAxis(px =>
px.MajorGridLines(mg => mg.Width(0))
.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).PrimaryYAxis(py => py.LabelFormat("{value}˚C")
.Minimum(0)
.Maximum(40)
.MajorTickLines(mt => mt.Width(0))
.LineStyle(ls => ls.Width(0))
).Title("Monthly Temperature Range").Render()
public IActionResult Index ()
{
List<ChartData> chartData = new List<ChartData>
{
new ChartData { x = "Jan", high = 14, low = 4, high1 = 29, low1 = 19 },
new ChartData { x = "Feb", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Mar", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Apr", high = 22, low = 12, high1 = 37, low1 = 27 },
new ChartData { x = "May", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Jun", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Jul", high = 15, low = 5, high1 = 30, low1 = 20 },
new ChartData { x = "Aug", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Sep", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Oct", high = 22, low = 12, high1 = 37, low1 = 27 },
new ChartData { x = "Nov", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Dec", high = 17, low = 7, high1 = 32, low1 = 22 }
};
ViewBag.dataSource = chartData;
return View();
}
public class ChartData
{
public string x;
public double high;
public double low;
public double high1;
public double low1;
}
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.SplineRangeArea).
XName("x").
High("high").
Low("low").
DataSource(ViewBag.dataSource).
Name("India").
Opacity(0.5)
Add();
}).PrimaryXAxis(px =>
px.MajorGridLines(mg => mg.Width(0))
.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).PrimaryYAxis(py => py.LabelFormat("{value}˚C")
.Minimum(0)
.Maximum(40)
.MajorTickLines(mt => mt.Width(0))
.LineStyle(ls => ls.Width(0))
).Title("Monthly Temperature Range").Render()
public IActionResult Index ()
{
List<ChartData> chartData = new List<ChartData>
{
new ChartData { x = "Jan", high = 14, low = 4, high1 = 29, low1 = 19 },
new ChartData { x = "Feb", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Mar", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Apr", high = 22, low = 12, high1 = 37, low1 = 27 },
new ChartData { x = "May", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Jun", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Jul", high = 15, low = 5, high1 = 30, low1 = 20 },
new ChartData { x = "Aug", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Sep", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Oct", high = 22, low = 12, high1 = 37, low1 = 27 },
new ChartData { x = "Nov", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Dec", high = 17, low = 7, high1 = 32, low1 = 22 }
};
ViewBag.dataSource = chartData;
return View();
}
public class ChartData
{
public string x;
public double high;
public double low;
public double high1;
public double low1;
}
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.SplineRangeArea).
XName("x").
High("high").
Low("low").
DataSource(ViewBag.dataSource).
DashArray("5,5").
Border(ViewBag.border).
Name("India").
Add();
}).PrimaryXAxis(px =>
px.MajorGridLines(mg => mg.Width(0))
.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).PrimaryYAxis(py => py.LabelFormat("{value}˚C")
.Minimum(0)
.Maximum(40)
.MajorTickLines(mt => mt.Width(0))
.LineStyle(ls => ls.Width(0))
).Title("Monthly Temperature Range").Render()
public IActionResult Index ()
{
List<ChartData> chartData = new List<ChartData>
{
new ChartData { x = "Jan", high = 14, low = 4, high1 = 29, low1 = 19 },
new ChartData { x = "Feb", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Mar", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Apr", high = 22, low = 12, high1 = 37, low1 = 27 },
new ChartData { x = "May", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Jun", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Jul", high = 15, low = 5, high1 = 30, low1 = 20 },
new ChartData { x = "Aug", high = 17, low = 7, high1 = 32, low1 = 22 },
new ChartData { x = "Sep", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Oct", high = 22, low = 12, high1 = 37, low1 = 27 },
new ChartData { x = "Nov", high = 20, low = 10, high1 = 35, low1 = 25 },
new ChartData { x = "Dec", high = 17, low = 7, high1 = 32, low1 = 22 }
};
ViewBag.dataSource = chartData;
ChartBorder border = new ChartBorder();
border.Width = 2;
border.Color = "#ff4251";
ViewBag.border = border;
return View();
}
public class ChartData
{
public string x;
public double high;
public double low;
public double high1;
public double low1;
}
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.SplineRangeArea).
XName("x").
High("high").
Low("low").
EmptyPointSettings(ViewBag.empty).
DataSource(ViewBag.dataSource).
Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Render()
public ActionResult Index()
{
List<AxisLabelData> chartData = new List<AxisLabelData>
{
new AxisLabelData { x= "Sun", low= 2.5, high= 9.8 },
new AxisLabelData { x= "Mon", low= 4.7, high= 11.4 },
new AxisLabelData { x= "Tue", low= null, high= 14.4 },
new AxisLabelData { x= "Wed", low= 9.6, high= 17.2 },
new AxisLabelData { x= "Thu", low= 7.5 },
new AxisLabelData { x= "Fri", low= 3.0, high= 10.5 },
new AxisLabelData { x= "Sat", low= 1.2, high= 7.9 }
};
ViewBag.dataSource = chartData;
ChartEmptyPointSettings emptyPointSettings = new ChartEmptyPointSettings();
emptyPointSettings.Mode = EmptyPointMode.Zero;
ViewBag.empty = emptyPointSettings;
return View();
}
public class AxisLabelData
{
public string x;
public double low;
public double high;
}
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.SplineRangeArea).
XName("x").
High("high").
Low("low").
EmptyPointSettings(ViewBag.empty).
DataSource(ViewBag.dataSource).
Marker(ViewBag.marker).
Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Render()
public ActionResult Index()
{
List<AxisLabelData> chartData = new List<AxisLabelData>
{
new AxisLabelData { x= "Sun", low= 2.5, high= 9.8 },
new AxisLabelData { x= "Mon", low= 4.7, high= 11.4 },
new AxisLabelData { x= "Tue", low= null, high= 14.4 },
new AxisLabelData { x= "Wed", low= 9.6, high= 17.2 },
new AxisLabelData { x= "Thu", low= 7.5 },
new AxisLabelData { x= "Fri", low= 3.0, high= 10.5 },
new AxisLabelData { x= "Sat", low= 1.2, high= 7.9 }
};
ViewBag.dataSource = chartData;
ChartEmptyPointSettings emptyPointSettings = new ChartEmptyPointSettings();
emptyPointSettings.Mode = EmptyPointMode.Average;
emptyPointSettings.Fill = "red";
ViewBag.empty = emptyPointSettings;
ChartMarkerSettings markerSettings = new ChartMarkerSettings();
markerSettings.Visible = true;
markerSettings.Width = 7;
markerSettings.Height = 7;
markerSettings.IsFilled = true;
ViewBag.marker = markerSettings;
return View();
}
public class AxisLabelData
{
public string x;
public double low;
public double high;
}
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.SplineRangeArea).
XName("x").
High("high").
Low("low").
EmptyPointSettings(ViewBag.empty).
DataSource(ViewBag.dataSource).
Marker(ViewBag.marker).
Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Render()
public ActionResult Index()
{
List<AxisLabelData> chartData = new List<AxisLabelData>
{
new AxisLabelData { x= "Sun", low= 2.5, high= 9.8 },
new AxisLabelData { x= "Mon", low= 4.7, high= 11.4 },
new AxisLabelData { x= "Tue", low= null, high= 14.4 },
new AxisLabelData { x= "Wed", low= 9.6, high= 17.2 },
new AxisLabelData { x= "Thu", low= 7.5 },
new AxisLabelData { x= "Fri", low= 3.0, high= 10.5 },
new AxisLabelData { x= "Sat", low= 1.2, high= 7.9 }
};
ViewBag.dataSource = chartData;
ChartEmptyPointSettings emptyPointSettings = new ChartEmptyPointSettings();
emptyPointSettings.Mode = EmptyPointMode.Zero;
emptyPointSettings.Border.Width = 2;
emptyPointSettings.Border.Color = "green";
ViewBag.empty = emptyPointSettings;
ChartMarkerSettings markerSettings = new ChartMarkerSettings();
markerSettings.Visible = true;
markerSettings.Width = 7;
markerSettings.Height = 7;
markerSettings.IsFilled = true;
ViewBag.marker = markerSettings;
return View();
}
public class AxisLabelData
{
public string x;
public double low;
public double high;
}
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.SplineRangeArea).
XName("x").
High("high").
Low("low").
DataSource(ViewBag.dataSource).
Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Render()
<script>
function changeColor(args) {
args.fill = '#ff6347';
}
</script>
public ActionResult Index()
{
List<AxisLabelData> chartData = new List<AxisLabelData>
{
new AxisLabelData { x= "Sun", low= 2.5, high= 9.8 },
new AxisLabelData { x= "Mon", low= 4.7, high= 11.4 },
new AxisLabelData { x= "Tue", low= 6.4, high= 14.4 },
new AxisLabelData { x= "Wed", low= 9.6, high= 17.2 },
new AxisLabelData { x= "Thu", low= 7.5, high= 15.1 },
new AxisLabelData { x= "Fri", low= 3.0, high= 10.5 },
new AxisLabelData { x= "Sat", low= 1.2, high= 7.9 }
};
ViewBag.dataSource = chartData;
return View();
}
public class AxisLabelData
{
public string x;
public double low;
public double high;
}
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.SplineRangeArea).
XName("x").
High("high").
Low("low").
DataSource(ViewBag.dataSource).
Marker(ViewBag.marker).
Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).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 { x= "Sun", low= 2.5, high= 9.8 },
new AxisLabelData { x= "Mon", low= 4.7, high= 11.4 },
new AxisLabelData { x= "Tue", low= 6.4, high= 14.4 },
new AxisLabelData { x= "Wed", low= 9.6, high= 17.2 },
new AxisLabelData { x= "Thu", low= 7.5, high= 15.1 },
new AxisLabelData { x= "Fri", low= 3.0, high= 10.5 },
new AxisLabelData { x= "Sat", low= 1.2, high= 7.9 }
};
ViewBag.dataSource = chartData;
return View();
}
public class AxisLabelData
{
public string x;
public double low;
public double high;
}