Stacked Line Chart in ASP.NET MVC Charts Component
30 Sep 202424 minutes to read
Stacked Line
To render a stacked line 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 StackingLine in your chart configuration. This indicates that the data should be represented as a stacked line chart, allowing multiple data series to be stacked on top of each other. This makes it easier to compare the contribution of each series to the total over a specific period.
@Html.EJS().Chart("container-vertical").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y").Width(2).DataSource(ViewBag.dataSource)
.Name("John").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y1").Width(2).DataSource(ViewBag.dataSource)
.Name("Peter").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y2").Width(2).DataSource(ViewBag.dataSource)
.Name("Steve").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y3").Width(2).DataSource(ViewBag.dataSource)
.Name("Charle").Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Title("Family Expense for Month").Render()
public ActionResult Index()
{
List<StackedLineChartData> chartData = new List<StackedLineChartData>
{
new StackedLineChartData { x= "Food", y= 90, y1= 40, y2= 70, y3= 120 },
new StackedLineChartData { x= "Transport", y= 80, y1= 90, y2= 110, y3= 70 },
new StackedLineChartData { x= "Medical", y= 50, y1= 80, y2= 120, y3= 50 },
new StackedLineChartData { x= "Clothes", y= 70, y1= 30, y2= 60, y3= 180 },
new StackedLineChartData { x= "Personal Care", y= 30, y1= 80, y2= 80, y3= 30 },
new StackedLineChartData { x= "Books", y= 10, y1= 40, y2= 30, y3= 270 },
new StackedLineChartData { x= "Fitness", y= 100,y1= 30, y2= 70, y3= 40 },
new StackedLineChartData { x= "Electricity", y= 55, y1= 95, y2= 55, y3= 75 },
new StackedLineChartData { x= "Tax", y= 20, y1= 50, y2= 40, y3= 65 },
new StackedLineChartData { x= "Pet Care", y= 40, y1= 20, y2= 80, y3= 95 },
new StackedLineChartData { x= "Education", y= 45, y1= 15, y2= 45, y3= 195 },
new StackedLineChartData { x= "Entertainment", y= 75, y1= 45, y2= 65, y3= 115 }
};
ViewBag.dataSource = chartData;
return View();
}
public class StackedLineChartData
{
public string x;
public double y;
public double y1;
public double y2;
public double y3;
}
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-vertical").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y").Width(2).DataSource(ViewBag.dataSource)
.Name("John").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y1").Width(2).DataSource(ViewBag.dataSource)
.Name("Peter").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y2").Width(2).DataSource(ViewBag.dataSource)
.Name("Steve").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y3").Width(2).DataSource(ViewBag.dataSource)
.Name("Charle").Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Title("Family Expense for Month").Render()
public ActionResult Index()
{
List<StackedLineChartData> chartData = new List<StackedLineChartData>
{
new StackedLineChartData { x= "Food", y= 90, y1= 40, y2= 70, y3= 120 },
new StackedLineChartData { x= "Transport", y= 80, y1= 90, y2= 110, y3= 70 },
new StackedLineChartData { x= "Medical", y= 50, y1= 80, y2= 120, y3= 50 },
new StackedLineChartData { x= "Clothes", y= 70, y1= 30, y2= 60, y3= 180 },
new StackedLineChartData { x= "Personal Care", y= 30, y1= 80, y2= 80, y3= 30 },
new StackedLineChartData { x= "Books", y= 10, y1= 40, y2= 30, y3= 270 },
new StackedLineChartData { x= "Fitness", y= 100,y1= 30, y2= 70, y3= 40 },
new StackedLineChartData { x= "Electricity", y= 55, y1= 95, y2= 55, y3= 75 },
new StackedLineChartData { x= "Tax", y= 20, y1= 50, y2= 40, y3= 65 },
new StackedLineChartData { x= "Pet Care", y= 40, y1= 20, y2= 80, y3= 95 },
new StackedLineChartData { x= "Education", y= 45, y1= 15, y2= 45, y3= 195 },
new StackedLineChartData { x= "Entertainment", y= 75, y1= 45, y2= 65, y3= 115 }
};
ViewBag.dataSource = chartData;
return View();
}
public class StackedLineChartData
{
public string x;
public double y;
public double y1;
public double y2;
public double y3;
}
Series customization
The following properties can be used to customize the stacked line
series.
Fill
The Fill
property determines the color applied to the series.
@Html.EJS().Chart("container-vertical").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y").DataSource(ViewBag.dataSource)
.Name("John").Fill("#ff4251").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y1").DataSource(ViewBag.dataSource)
.Name("Peter").Fill("#4C4C4C").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y2").DataSource(ViewBag.dataSource)
.Name("Steve").Fill("#794F1B").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y3").DataSource(ViewBag.dataSource)
.Name("Charle").Fill("#1a9a6f").Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Title("Family Expense for Month").Render()
public ActionResult Index()
{
List<StackedLineChartData> chartData = new List<StackedLineChartData>
{
new StackedLineChartData { x= "Food", y= 90, y1= 40, y2= 70, y3= 120 },
new StackedLineChartData { x= "Transport", y= 80, y1= 90, y2= 110, y3= 70 },
new StackedLineChartData { x= "Medical", y= 50, y1= 80, y2= 120, y3= 50 },
new StackedLineChartData { x= "Clothes", y= 70, y1= 30, y2= 60, y3= 180 },
new StackedLineChartData { x= "Personal Care", y= 30, y1= 80, y2= 80, y3= 30 },
new StackedLineChartData { x= "Books", y= 10, y1= 40, y2= 30, y3= 270 },
new StackedLineChartData { x= "Fitness", y= 100,y1= 30, y2= 70, y3= 40 },
new StackedLineChartData { x= "Electricity", y= 55, y1= 95, y2= 55, y3= 75 },
new StackedLineChartData { x= "Tax", y= 20, y1= 50, y2= 40, y3= 65 },
new StackedLineChartData { x= "Pet Care", y= 40, y1= 20, y2= 80, y3= 95 },
new StackedLineChartData { x= "Education", y= 45, y1= 15, y2= 45, y3= 195 },
new StackedLineChartData { x= "Entertainment", y= 75, y1= 45, y2= 65, y3= 115 }
};
ViewBag.dataSource = chartData;
return View();
}
public class StackedLineChartData
{
public string x;
public double y;
public double y1;
public double y2;
public double y3;
}
The Fill
property can be used to apply a gradient color to the stacked line 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="gradient1">
<stop offset="0%" style="stop-color:coral;stop-opacity:5" />
<stop offset="50%" style="stop-color:mediumseagreen;stop-opacity:5" />
</linearGradient>
</defs>
</svg>
<svg style="width:1px; height:1px">
<defs>
<linearGradient id="gradient2">
<stop offset="0%" style="stop-color:darkred;stop-opacity:5" />
<stop offset="50%" style="stop-color:darkorange;stop-opacity:5" />
</linearGradient>
</defs>
</svg>
<svg style="width:1px; height:1px">
<defs>
<linearGradient id="gradient3">
<stop offset="0%" style="stop-color:darkmagenta;stop-opacity:5" />
<stop offset="50%" style="stop-color:darkcyan;stop-opacity:5" />
</linearGradient>
</defs>
</svg>
<svg style="width:1px; height:1px">
<defs>
<linearGradient id="gradient4">
<stop offset="0%" style="stop-color:darkviolet;stop-opacity:5" />
<stop offset="50%" style="stop-color:darkgoldenrod;stop-opacity:5" />
</linearGradient>
</defs>
</svg>
@Html.EJS().Chart("container-vertical").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y").DataSource(ViewBag.dataSource)
.Name("John").Fill("url(#gradient1)").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y1").DataSource(ViewBag.dataSource)
.Name("Peter").Fill("url(#gradient2)").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y2").DataSource(ViewBag.dataSource)
.Name("Steve").Fill("url(#gradient3)").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y3").DataSource(ViewBag.dataSource)
.Name("Charle").Fill("url(#gradient4)").Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Title("Family Expense for Month").Render
public ActionResult Index()
{
List<StackedLineChartData> chartData = new List<StackedLineChartData>
{
new StackedLineChartData { x= "Food", y= 90, y1= 40, y2= 70, y3= 120 },
new StackedLineChartData { x= "Transport", y= 80, y1= 90, y2= 110, y3= 70 },
new StackedLineChartData { x= "Medical", y= 50, y1= 80, y2= 120, y3= 50 },
new StackedLineChartData { x= "Clothes", y= 70, y1= 30, y2= 60, y3= 180 },
new StackedLineChartData { x= "Personal Care", y= 30, y1= 80, y2= 80, y3= 30 },
new StackedLineChartData { x= "Books", y= 10, y1= 40, y2= 30, y3= 270 },
new StackedLineChartData { x= "Fitness", y= 100,y1= 30, y2= 70, y3= 40 },
new StackedLineChartData { x= "Electricity", y= 55, y1= 95, y2= 55, y3= 75 },
new StackedLineChartData { x= "Tax", y= 20, y1= 50, y2= 40, y3= 65 },
new StackedLineChartData { x= "Pet Care", y= 40, y1= 20, y2= 80, y3= 95 },
new StackedLineChartData { x= "Education", y= 45, y1= 15, y2= 45, y3= 195 },
new StackedLineChartData { x= "Entertainment", y= 75, y1= 45, y2= 65, y3= 115 }
};
ViewBag.dataSource = chartData;
return View();
}
public class StackedLineChartData
{
public string x;
public double y;
public double y1;
public double y2;
public double y3;
}
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-vertical").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).Opacity(0.7).XName("x").YName("y").DataSource(ViewBag.dataSource)
.Name("John").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).Opacity(0.7).XName("x").YName("y1").DataSource(ViewBag.dataSource)
.Name("Peter").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).Opacity(0.7).XName("x").YName("y2").DataSource(ViewBag.dataSource)
.Name("Steve").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).Opacity(0.7).XName("x").YName("y3").DataSource(ViewBag.dataSource)
.Name("Charle").Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Title("Family Expense for Month").Render()
public ActionResult Index()
{
List<StackedLineChartData> chartData = new List<StackedLineChartData>
{
new StackedLineChartData { x= "Food", y= 90, y1= 40, y2= 70, y3= 120 },
new StackedLineChartData { x= "Transport", y= 80, y1= 90, y2= 110, y3= 70 },
new StackedLineChartData { x= "Medical", y= 50, y1= 80, y2= 120, y3= 50 },
new StackedLineChartData { x= "Clothes", y= 70, y1= 30, y2= 60, y3= 180 },
new StackedLineChartData { x= "Personal Care", y= 30, y1= 80, y2= 80, y3= 30 },
new StackedLineChartData { x= "Books", y= 10, y1= 40, y2= 30, y3= 270 },
new StackedLineChartData { x= "Fitness", y= 100,y1= 30, y2= 70, y3= 40 },
new StackedLineChartData { x= "Electricity", y= 55, y1= 95, y2= 55, y3= 75 },
new StackedLineChartData { x= "Tax", y= 20, y1= 50, y2= 40, y3= 65 },
new StackedLineChartData { x= "Pet Care", y= 40, y1= 20, y2= 80, y3= 95 },
new StackedLineChartData { x= "Education", y= 45, y1= 15, y2= 45, y3= 195 },
new StackedLineChartData { x= "Entertainment", y= 75, y1= 45, y2= 65, y3= 115 }
};
ViewBag.dataSource = chartData;
return View();
}
public class StackedLineChartData
{
public string x;
public double y;
public double y1;
public double y2;
public double y3;
}
Dash array
The DashArray
property determines the pattern of dashes and gaps in the series.
@Html.EJS().Chart("container-vertical").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y").DashArray("5,5").DataSource(ViewBag.dataSource)
.Name("John").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y1").DashArray("5,5").DataSource(ViewBag.dataSource)
.Name("Peter").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y2").DashArray("5,5").DataSource(ViewBag.dataSource)
.Name("Steve").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y3").DashArray("5,5").DataSource(ViewBag.dataSource)
.Name("Charle").Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Title("Family Expense for Month").Render()
public ActionResult Index()
{
List<StackedLineChartData> chartData = new List<StackedLineChartData>
{
new StackedLineChartData { x= "Food", y= 90, y1= 40, y2= 70, y3= 120 },
new StackedLineChartData { x= "Transport", y= 80, y1= 90, y2= 110, y3= 70 },
new StackedLineChartData { x= "Medical", y= 50, y1= 80, y2= 120, y3= 50 },
new StackedLineChartData { x= "Clothes", y= 70, y1= 30, y2= 60, y3= 180 },
new StackedLineChartData { x= "Personal Care", y= 30, y1= 80, y2= 80, y3= 30 },
new StackedLineChartData { x= "Books", y= 10, y1= 40, y2= 30, y3= 270 },
new StackedLineChartData { x= "Fitness", y= 100,y1= 30, y2= 70, y3= 40 },
new StackedLineChartData { x= "Electricity", y= 55, y1= 95, y2= 55, y3= 75 },
new StackedLineChartData { x= "Tax", y= 20, y1= 50, y2= 40, y3= 65 },
new StackedLineChartData { x= "Pet Care", y= 40, y1= 20, y2= 80, y3= 95 },
new StackedLineChartData { x= "Education", y= 45, y1= 15, y2= 45, y3= 195 },
new StackedLineChartData { x= "Entertainment", y= 75, y1= 45, y2= 65, y3= 115 }
};
ViewBag.dataSource = chartData;
return View();
}
public class StackedLineChartData
{
public string x;
public double y;
public double y1;
public double y2;
public double y3;
}
Width
The Width
property specifies the stroke width applied to the series.
@Html.EJS().Chart("container-vertical").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y").Width(2).DataSource(ViewBag.dataSource)
.Name("John").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y1").Width(2).DataSource(ViewBag.dataSource)
.Name("Peter").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y2").Width(2).DataSource(ViewBag.dataSource)
.Name("Steve").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y3").Width(2).DataSource(ViewBag.dataSource)
.Name("Charle").Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Title("Family Expense for Month").Render()
public ActionResult Index()
{
List<StackedLineChartData> chartData = new List<StackedLineChartData>
{
new StackedLineChartData { x= "Food", y= 90, y1= 40, y2= 70, y3= 120 },
new StackedLineChartData { x= "Transport", y= 80, y1= 90, y2= 110, y3= 70 },
new StackedLineChartData { x= "Medical", y= 50, y1= 80, y2= 120, y3= 50 },
new StackedLineChartData { x= "Clothes", y= 70, y1= 30, y2= 60, y3= 180 },
new StackedLineChartData { x= "Personal Care", y= 30, y1= 80, y2= 80, y3= 30 },
new StackedLineChartData { x= "Books", y= 10, y1= 40, y2= 30, y3= 270 },
new StackedLineChartData { x= "Fitness", y= 100,y1= 30, y2= 70, y3= 40 },
new StackedLineChartData { x= "Electricity", y= 55, y1= 95, y2= 55, y3= 75 },
new StackedLineChartData { x= "Tax", y= 20, y1= 50, y2= 40, y3= 65 },
new StackedLineChartData { x= "Pet Care", y= 40, y1= 20, y2= 80, y3= 95 },
new StackedLineChartData { x= "Education", y= 45, y1= 15, y2= 45, y3= 195 },
new StackedLineChartData { x= "Entertainment", y= 75, y1= 45, y2= 65, y3= 115 }
};
ViewBag.dataSource = chartData;
return View();
}
public class StackedLineChartData
{
public string x;
public double y;
public double y1;
public double y2;
public double y3;
}
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-vertical").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y").DataSource(ViewBag.dataSource)
.Name("John").EmptyPointSettings(ViewBag.emptyPoint).Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y1").DataSource(ViewBag.dataSource)
.Name("Peter").EmptyPointSettings(ViewBag.emptyPoint).Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y2").DataSource(ViewBag.dataSource)
.Name("Steve").EmptyPointSettings(ViewBag.emptyPoint).Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y3").DataSource(ViewBag.dataSource)
.Name("Charle").EmptyPointSettings(ViewBag.emptyPoint).Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Title("Family Expense for Month").Render()
public ActionResult Index()
{
List<StackedLineChartData> chartData = new List<StackedLineChartData>
{
new StackedLineChartData { x= "Food", y= 90, y1= 40, y2= 70, y3= 120 },
new StackedLineChartData { x= "Transport", y= 80, y1= 90, y2= 110, y3= 70 },
new StackedLineChartData { x= "Medical", y= 50, y1= 80, y2= 120, y3= 50 },
new StackedLineChartData { x= "Clothes", y= null, y1= 30, y2= 60, y3= 180 },
new StackedLineChartData { x= "Personal Care", y= 30, y1= 80, y2= 80, y3= 30 },
new StackedLineChartData { x= "Books", y= 10, y1= 40, y2= 30, y3= 270 },
new StackedLineChartData { x= "Fitness", y= 100,y1= 30, y2= 70, y3= 40 },
new StackedLineChartData { x= "Electricity", y= 55, y1= 95, y2= null, y3= 75 },
new StackedLineChartData { x= "Tax", y= 20, y1= 50, y2= 40, y3= 65 },
new StackedLineChartData { x= "Pet Care", y= 40, y1= 20, y2= 80, y3= 95 },
new StackedLineChartData { x= "Education", y= 45, y1= 15, y2= 45, y3= 195 },
new StackedLineChartData { x= "Entertainment", y= 75, y1= 45, y2= 65, y3= 115 }
};
ViewBag.dataSource = chartData;
ChartEmptyPointSettings chartEmptyPointSettings = new ChartEmptyPointSettings();
chartEmptyPointSettings.Mode = EmptyPointMode.Average;
ViewBag.emptyPoint = chartEmptyPointSettings;
return View();
}
public class StackedLineChartData
{
public string x;
public double? y;
public double y1;
public double? y2;
public double y3;
}
Fill
Use the Fill
property to customize the fill color of empty points in the series.
@Html.EJS().Chart("container-vertical").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y").DataSource(ViewBag.dataSource)
.Name("John").EmptyPointSettings(ViewBag.emptyPoint).Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y1").DataSource(ViewBag.dataSource)
.Name("Peter").EmptyPointSettings(ViewBag.emptyPoint).Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y2").DataSource(ViewBag.dataSource)
.Name("Steve").EmptyPointSettings(ViewBag.emptyPoint).Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y3").DataSource(ViewBag.dataSource)
.Name("Charle").EmptyPointSettings(ViewBag.emptyPoint).Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Title("Family Expense for Month").Render()
public ActionResult Index()
{
List<StackedLineChartData> chartData = new List<StackedLineChartData>
{
new StackedLineChartData { x= "Food", y= 90, y1= 40, y2= 70, y3= 120 },
new StackedLineChartData { x= "Transport", y= 80, y1= 90, y2= 110, y3= 70 },
new StackedLineChartData { x= "Medical", y= 50, y1= 80, y2= 120, y3= 50 },
new StackedLineChartData { x= "Clothes", y= null, y1= 30, y2= 60, y3= 180 },
new StackedLineChartData { x= "Personal Care", y= 30, y1= 80, y2= 80, y3= 30 },
new StackedLineChartData { x= "Books", y= 10, y1= 40, y2= 30, y3= 270 },
new StackedLineChartData { x= "Fitness", y= 100,y1= 30, y2= 70, y3= 40 },
new StackedLineChartData { x= "Electricity", y= 55, y1= 95, y2= null, y3= 75 },
new StackedLineChartData { x= "Tax", y= 20, y1= 50, y2= 40, y3= 65 },
new StackedLineChartData { x= "Pet Care", y= 40, y1= 20, y2= 80, y3= 95 },
new StackedLineChartData { x= "Education", y= 45, y1= 15, y2= 45, y3= 195 },
new StackedLineChartData { x= "Entertainment", y= 75, y1= 45, y2= 65, y3= 115 }
};
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 StackedLineChartData
{
public string x;
public double? y;
public double y1;
public double? y2;
public double y3;
}
Border
Use the Border
property to customize the width and color of the border for empty points.
@Html.EJS().Chart("container-vertical").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y").DataSource(ViewBag.dataSource)
.Name("John").EmptyPointSettings(ViewBag.emptyPoint).Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y1").DataSource(ViewBag.dataSource)
.Name("Peter").EmptyPointSettings(ViewBag.emptyPoint).Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y2").DataSource(ViewBag.dataSource)
.Name("Steve").EmptyPointSettings(ViewBag.emptyPoint).Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y3").DataSource(ViewBag.dataSource)
.Name("Charle").EmptyPointSettings(ViewBag.emptyPoint).Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Title("Family Expense for Month").Render()
public ActionResult Index()
{
List<StackedLineChartData> chartData = new List<StackedLineChartData>
{
new StackedLineChartData { x= "Food", y= 90, y1= 40, y2= 70, y3= 120 },
new StackedLineChartData { x= "Transport", y= 80, y1= 90, y2= 110, y3= 70 },
new StackedLineChartData { x= "Medical", y= 50, y1= 80, y2= 120, y3= 50 },
new StackedLineChartData { x= "Clothes", y= null, y1= 30, y2= 60, y3= 180 },
new StackedLineChartData { x= "Personal Care", y= 30, y1= 80, y2= 80, y3= 30 },
new StackedLineChartData { x= "Books", y= 10, y1= 40, y2= 30, y3= 270 },
new StackedLineChartData { x= "Fitness", y= 100,y1= 30, y2= 70, y3= 40 },
new StackedLineChartData { x= "Electricity", y= 55, y1= 95, y2= null, y3= 75 },
new StackedLineChartData { x= "Tax", y= 20, y1= 50, y2= 40, y3= 65 },
new StackedLineChartData { x= "Pet Care", y= 40, y1= 20, y2= 80, y3= 95 },
new StackedLineChartData { x= "Education", y= 45, y1= 15, y2= 45, y3= 195 },
new StackedLineChartData { x= "Entertainment", y= 75, y1= 45, y2= 65, y3= 115 }
};
ViewBag.dataSource = chartData;
ChartEmptyPointSettings chartEmptyPointSettings = new ChartEmptyPointSettings();
chartEmptyPointSettings.Mode = EmptyPointMode.Average;
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 StackedLineChartData
{
public string x;
public double? y;
public double y1;
public double? y2;
public double y3;
}
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-vertical").SeriesRender("changeColor").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y").Width(2).DataSource(ViewBag.dataSource)
.Name("John").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y1").Width(2).DataSource(ViewBag.dataSource)
.Name("Peter").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y2").Width(2).DataSource(ViewBag.dataSource)
.Name("Steve").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y3").Width(2).DataSource(ViewBag.dataSource)
.Name("Charle").Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Title("Family Expense for Month").Render()
<script>
function changeColor(args) {
if (args.series.index === 0) {
args.fill = '#ff4251';
}
else if (args.series.index === 1) {
args.fill = '#4C4C4C';
}
else if (args.series.index === 2) {
args.fill = '#794F1B';
}
else if (args.series.index === 3) {
args.fill = '#1a9a6f';
}
}
</script>
public ActionResult Index()
{
List<StackedLineChartData> chartData = new List<StackedLineChartData>
{
new StackedLineChartData { x= "Food", y= 90, y1= 40, y2= 70, y3= 120 },
new StackedLineChartData { x= "Transport", y= 80, y1= 90, y2= 110, y3= 70 },
new StackedLineChartData { x= "Medical", y= 50, y1= 80, y2= 120, y3= 50 },
new StackedLineChartData { x= "Clothes", y= 70, y1= 30, y2= 60, y3= 180 },
new StackedLineChartData { x= "Personal Care", y= 30, y1= 80, y2= 80, y3= 30 },
new StackedLineChartData { x= "Books", y= 10, y1= 40, y2= 30, y3= 270 },
new StackedLineChartData { x= "Fitness", y= 100,y1= 30, y2= 70, y3= 40 },
new StackedLineChartData { x= "Electricity", y= 55, y1= 95, y2= 55, y3= 75 },
new StackedLineChartData { x= "Tax", y= 20, y1= 50, y2= 40, y3= 65 },
new StackedLineChartData { x= "Pet Care", y= 40, y1= 20, y2= 80, y3= 95 },
new StackedLineChartData { x= "Education", y= 45, y1= 15, y2= 45, y3= 195 },
new StackedLineChartData { x= "Entertainment", y= 75, y1= 45, y2= 65, y3= 115 }
};
ViewBag.dataSource = chartData;
return View();
}
public class StackedLineChartData
{
public string x;
public double y;
public double y1;
public double y2;
public double y3;
}
Point render
The PointRender
event allows you to customize each data point before it is rendered on the chart.
@Html.EJS().Chart("container-vertical").PointRender("changeColor").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y").Width(2).DataSource(ViewBag.dataSource)
.Name("John").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y1").Width(2).DataSource(ViewBag.dataSource)
.Name("Peter").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y2").Width(2).DataSource(ViewBag.dataSource)
.Name("Steve").Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.StackingLine)
.Marker(mkr => mkr.Visible(true)).XName("x").YName("y3").Width(2).DataSource(ViewBag.dataSource)
.Name("Charle").Add();
}).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)).Title("Family Expense for Month").Render()
<script>
function changeColor(args) {
if (args.point.y < 100) {
args.fill = '#ff6347';
}
else {
args.fill = '#009cb8';
}
}
</script>
public ActionResult Index()
{
List<StackedLineChartData> chartData = new List<StackedLineChartData>
{
new StackedLineChartData { x= "Food", y= 90, y1= 40, y2= 70, y3= 120 },
new StackedLineChartData { x= "Transport", y= 80, y1= 90, y2= 110, y3= 70 },
new StackedLineChartData { x= "Medical", y= 50, y1= 80, y2= 120, y3= 50 },
new StackedLineChartData { x= "Clothes", y= 70, y1= 30, y2= 60, y3= 180 },
new StackedLineChartData { x= "Personal Care", y= 30, y1= 80, y2= 80, y3= 30 },
new StackedLineChartData { x= "Books", y= 10, y1= 40, y2= 30, y3= 270 },
new StackedLineChartData { x= "Fitness", y= 100,y1= 30, y2= 70, y3= 40 },
new StackedLineChartData { x= "Electricity", y= 55, y1= 95, y2= 55, y3= 75 },
new StackedLineChartData { x= "Tax", y= 20, y1= 50, y2= 40, y3= 65 },
new StackedLineChartData { x= "Pet Care", y= 40, y1= 20, y2= 80, y3= 95 },
new StackedLineChartData { x= "Education", y= 45, y1= 15, y2= 45, y3= 195 },
new StackedLineChartData { x= "Entertainment", y= 75, y1= 45, y2= 65, y3= 115 }
};
ViewBag.dataSource = chartData;
return View();
}
public class StackedLineChartData
{
public string x;
public double y;
public double y1;
public double y2;
public double y3;
}