- Vertical chart
- Binding data with series
- Empty points
- Events
- See Also
Contact Support
Vertical Chart in ASP.NET MVC Charts Component
8 Oct 202421 minutes to read
Vertical chart
To draw a chart in a vertical manner, change the orientation of the axis using the IsTransposed
property, which is supported by all series types.
@Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Spline).
Marker(ViewBag.Marker).
XName("x").
YName("y").
DataSource(ViewBag.dataSource).
Name("Gold").
Width(2).
Add();
}). PrimaryXAxis(px =>
px.Interval(1)
.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).Title("Olympic Medal Counts - RIO").IsTransposed(true).Render()
public ActionResult Index()
{
List<VerticalData> chartData = new List<VerticalData>
{
new VerticalData{ x= 2005, y= 28 },
new VerticalData{ x= 2006, y= 25 },
new VerticalData{ x= 2007, y= 26 },
new VerticalData{ x= 2008, y= 27 },
new VerticalData{ x= 2009, y= 32 },
new VerticalData{ x= 2010, y= 35 },
new VerticalData{ x= 2011, y= 30 }
};
ViewBag.dataSource = chartData;
return View();
}
public class VerticalData
{
public double x;
public double y;
}
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.Spline).
Marker(ViewBag.Marker).
XName("x").
YName("y").
DataSource(ViewBag.dataSource).
Name("Gold").
Width(2).
Add();
}). PrimaryXAxis(px =>
px.Interval(1)
.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).Title("Olympic Medal Counts - RIO").IsTransposed(true).Render()
public ActionResult Index()
{
List<VerticalData> chartData = new List<VerticalData>
{
new VerticalData{ x= 2005, y= 28 },
new VerticalData{ x= 2006, y= 25 },
new VerticalData{ x= 2007, y= 26 },
new VerticalData{ x= 2008, y= 27 },
new VerticalData{ x= 2009, y= 32 },
new VerticalData{ x= 2010, y= 35 },
new VerticalData{ x= 2011, y= 30 }
};
ViewBag.dataSource = chartData;
return View();
}
public class VerticalData
{
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.Spline).
Marker(marker => marker.Visible(true)).
EmptyPointSettings(empty => empty.Mode(Syncfusion.EJ2.Charts.EmptyPointMode.Zero)).
XName("x").
YName("y").
DataSource(ViewBag.dataSource).
Name("Gold").
Width(2).
Add();
}).PrimaryXAxis(px =>
px.Interval(1)
.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).Title("Olympic Medal Counts - RIO").IsTransposed(true).Render()
public ActionResult Index()
{
List<VerticalData> chartData = new List<VerticalData>
{
new VerticalData{ x= 2005, y= 28 },
new VerticalData{ x= 2006, y= 25 },
new VerticalData{ x= 2007, y= null },
new VerticalData{ x= 2008, y= 27 },
new VerticalData{ x= 2009, y= 32 },
new VerticalData{ x= 2010, y= null },
new VerticalData{ x= 2011, y= 30 }
};
ViewBag.dataSource = chartData;
return View();
}
public class VerticalData
{
public double x;
public double y;
}
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).
Marker(marker => marker.Visible(true)).
EmptyPointSettings(empty => empty.Mode(Syncfusion.EJ2.Charts.EmptyPointMode.Zero).Fill("red")).
XName("x").
YName("y").
DataSource(ViewBag.dataSource).
Name("Gold").
Width(2).
Add();
}).PrimaryXAxis(px =>
px.Interval(1)
.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).Title("Olympic Medal Counts - RIO").IsTransposed(true).Render()
public ActionResult Index()
{
List<VerticalData> chartData = new List<VerticalData>
{
new VerticalData{ x= 2005, y= 28 },
new VerticalData{ x= 2006, y= 25 },
new VerticalData{ x= 2007, y= null },
new VerticalData{ x= 2008, y= 27 },
new VerticalData{ x= 2009, y= 32 },
new VerticalData{ x= 2010, y= null },
new VerticalData{ x= 2011, y= 30 }
};
ViewBag.dataSource = chartData;
return View();
}
public class VerticalData
{
public double x;
public double y;
}
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.Spline).
Marker(marker => marker.Visible(true)).
EmptyPointSettings(empty => empty.Mode(Syncfusion.EJ2.Charts.EmptyPointMode.Zero).Border(border => border.Width(2).Color("red"))).
XName("x").
YName("y").
DataSource(ViewBag.dataSource).
Name("Gold").
Width(2).
Add();
}).PrimaryXAxis(px =>
px.Interval(1)
.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).Title("Olympic Medal Counts - RIO").IsTransposed(true).Render()
public ActionResult Index()
{
List<VerticalData> chartData = new List<VerticalData>
{
new VerticalData{ x= 2005, y= 28 },
new VerticalData{ x= 2006, y= 25 },
new VerticalData{ x= 2007, y= null },
new VerticalData{ x= 2008, y= 27 },
new VerticalData{ x= 2009, y= 32 },
new VerticalData{ x= 2010, y= null },
new VerticalData{ x= 2011, y= 30 }
};
ViewBag.dataSource = chartData;
return View();
}
public class VerticalData
{
public double x;
public double y;
}
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.Spline).
XName("x").
YName("y").
DataSource(ViewBag.dataSource).
Name("Gold").
Width(2).
Add();
}). PrimaryXAxis(px =>
px.Interval(1)
.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).Title("Olympic Medal Counts - RIO").IsTransposed(true).Render()
<script>
function changeColor(args) {
args.fill = '#ff6347';
}
</script>
public ActionResult Index()
{
List<VerticalData> chartData = new List<VerticalData>
{
new VerticalData{ x= 2005, y= 28 },
new VerticalData{ x= 2006, y= 25 },
new VerticalData{ x= 2007, y= 26 },
new VerticalData{ x= 2008, y= 27 },
new VerticalData{ x= 2009, y= 32 },
new VerticalData{ x= 2010, y= 35 },
new VerticalData{ x= 2011, y= 30 }
};
ViewBag.dataSource = chartData;
return View();
}
public class VerticalData
{
public double x;
public double y;
}
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.Spline).
Marker(marker => marker.Visible(true)).
XName("x").
YName("y").
DataSource(ViewBag.dataSource).
Name("Gold").
Width(2).
Add();
}). PrimaryXAxis(px =>
px.Interval(1)
.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).Title("Olympic Medal Counts - RIO").IsTransposed(true).Render()
<script>
function changeColor(args) {
if (args.point.index % 2 !== 0) {
args.fill = '#ff6347';
}
else {
args.fill = '#009cb8';
}
}
</script>
public ActionResult Index()
{
List<VerticalData> chartData = new List<VerticalData>
{
new VerticalData{ x= 2005, y= 28 },
new VerticalData{ x= 2006, y= 25 },
new VerticalData{ x= 2007, y= 26 },
new VerticalData{ x= 2008, y= 27 },
new VerticalData{ x= 2009, y= 32 },
new VerticalData{ x= 2010, y= 35 },
new VerticalData{ x= 2011, y= 30 }
};
ViewBag.dataSource = chartData;
return View();
}
public class VerticalData
{
public double x;
public double y;
}