Legend in ASP.NET MVC 3D Circular Chart Component
18 Mar 202419 minutes to read
The legend provides information about the data points rendered in the 3D Circular Chart. It can be added by enabling the Visible option in the LegendSettings property.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Visible(true)).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 13 },
new CircularChartData { X = "Feb", Y = 13 },
new CircularChartData { X = "Mar", Y = 17 },
new CircularChartData { X = "Apr", Y = 13.5 }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
}Position and alignment
By using the Position property, the legend can be positioned at the Left, Right, Top or Bottom of the 3D Circular Chart. By default, the legend will be positioned to the right of the 3D Circular Chart. Additionally, you can align the legend to the Center, Far or Near of the chart using the Alignment property.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Position(Syncfusion.EJ2.Charts.LegendPosition.Top).Alignment(Syncfusion.EJ2.Charts.Alignment.Near)).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 13 },
new CircularChartData { X = "Feb", Y = 13 },
new CircularChartData { X = "Mar", Y = 17 },
new CircularChartData { X = "Apr", Y = 13.5 }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
}Legend reverse
You can reverse the order of the legend items by using the Reverse property in LegendSettings. By default, the legend for the first series in the collection will be placed first.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").LegendShape(Syncfusion.EJ2.Charts.LegendShape.Rectangle).DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Visible(true).Reverse(true)).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 13 },
new CircularChartData { X = "Feb", Y = 13 },
new CircularChartData { X = "Mar", Y = 17 },
new CircularChartData { X = "Apr", Y = 13.5 }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
}Legend shape
To change the legend shape, use the LegendShape property in the Series. By default, the legend shape is set to SeriesType.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").LegendShape(Syncfusion.EJ2.Charts.LegendShape.Rectangle).DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Visible(true)).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 13 },
new CircularChartData { X = "Feb", Y = 13 },
new CircularChartData { X = "Mar", Y = 17 },
new CircularChartData { X = "Apr", Y = 13.5 }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
}Legend size
The legend size can be changed by using the Width and Height properties in LegendSettings.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Width("150").Height("100").Border(br => br.Width(1).Color("pink"))).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 13 },
new CircularChartData { X = "Feb", Y = 13 },
new CircularChartData { X = "Mar", Y = 17 },
new CircularChartData { X = "Apr", Y = 13.5 }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
}Legend item size
The size of the legend items can be customized by using the ShapeHeight and ShapeWidth properties in LegendSettings.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.ShapeHeight(15).ShapeWidth(15)).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 13 },
new CircularChartData { X = "Feb", Y = 13 },
new CircularChartData { X = "Mar", Y = 17 },
new CircularChartData { X = "Apr", Y = 13.5 }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
}Legend paging
Paging will be enabled by default when the legend items exceed the legend bounds. Each legend item can be viewed by navigating between the pages using navigation buttons.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Width("80").Height("150")).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 3 },
new CircularChartData { X = "Feb", Y = 3.5 },
new CircularChartData { X = "Mar", Y = 7 },
new CircularChartData { X = "Apr", Y = 13.5 },
new CircularChartData { X = "May", Y = 19 },
new CircularChartData { X = "Jun", Y = 23.5 },
new CircularChartData { X = "Jul", Y = 26 },
new CircularChartData { X = "Aug", Y = 25 },
new CircularChartData { X = "Sep", Y = 21 },
new CircularChartData { X = "Oct", Y = 15 },
new CircularChartData { X = "Nov", Y = 15 },
new CircularChartData { X = "Dec", Y = 15 }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
}Legend text wrap
When the legend text exceeds the container, the text can be wrapped using the TextWrap property in LegendSettings. End users can also wrap the legend text based on the MaximumLabelWidth property in LegendSettings.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").InnerRadius("40%").DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Visible(true).Position(Syncfusion.EJ2.Charts.LegendPosition.Right).TextWrap(Syncfusion.EJ2.Charts.TextWrap.Wrap).MaximumLabelWidth(60)).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Net-tution", Y = 21 },
new CircularChartData { X = "Private Gifts", Y = 8 },
new CircularChartData { X = "All Other", Y = 9 },
new CircularChartData { X = "Local Revenue", Y = 4 },
new CircularChartData { X = "State Revenue", Y = 21 },
new CircularChartData { X = "Federal Revenue", Y = 16 },
new CircularChartData { X = "Self-supporting Operations", Y = 21 }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
}Legend title
You can set a title for the legend using the Title property in LegendSettings. The Size, Color, Opacity, FontStyle, FontWeight, FontFamily, TextAlignment, and TextOverflow of the legend title can be customized using the TitleStyle property in LegendSettings.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Visible(true).Title("Months").Position(Syncfusion.EJ2.Charts.LegendPosition.Bottom)).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 13 },
new CircularChartData { X = "Feb", Y = 13 },
new CircularChartData { X = "Mar", Y = 17 },
new CircularChartData { X = "Apr", Y = 13.5 }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
}Arrow page navigation
The page number will always be visible when using legend paging. However, it is now possible to disable the page number and enable page navigation with the left and right arrows. To render the arrow page navigation, set the EnablePages property to false.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Width("260px").Height("50px").EnablePages(false).Position(Syncfusion.EJ2.Charts.LegendPosition.Bottom)).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 3 },
new CircularChartData { X = "Feb", Y = 3.5 },
new CircularChartData { X = "Mar", Y = 7 },
new CircularChartData { X = "Apr", Y = 13.5 },
new CircularChartData { X = "May", Y = 19 },
new CircularChartData { X = "Jun", Y = 23.5 },
new CircularChartData { X = "Jul", Y = 26 },
new CircularChartData { X = "Aug", Y = 25 },
new CircularChartData { X = "Sep", Y = 21 },
new CircularChartData { X = "Oct", Y = 15 },
new CircularChartData { X = "Nov", Y = 15 },
new CircularChartData { X = "Dec", Y = 15 }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
}Legend item padding
The ItemPadding property can be used to adjust the space between the legend items.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Width("260px").Height("50px").Position(Syncfusion.EJ2.Charts.LegendPosition.Bottom).ItemPadding(30)).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 3 },
new CircularChartData { X = "Feb", Y = 3.5 },
new CircularChartData { X = "Mar", Y = 7 },
new CircularChartData { X = "Apr", Y = 13.5 },
new CircularChartData { X = "May", Y = 19 },
new CircularChartData { X = "Jun", Y = 23.5 },
new CircularChartData { X = "Jul", Y = 26 },
new CircularChartData { X = "Aug", Y = 25 },
new CircularChartData { X = "Sep", Y = 21 },
new CircularChartData { X = "Oct", Y = 15 },
new CircularChartData { X = "Nov", Y = 15 },
new CircularChartData { X = "Dec", Y = 15 }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
}