Data Label in ASP.NET MVC 3D Circular Chart Component
A data label refers to a label associated with specific data points. It can be added to a 3D Circular Chart series by enabling the Visible option in the DataLabel property. By default, the labels will arrange themselves smartly to avoid overlapping.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").DataLabel(dl => dl.Visible(true)).DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Visible(false)).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 13 },
new CircularChartData { X = "Feb", Y = 13.5 },
new CircularChartData { X = "Mar", Y = 7 },
new CircularChartData { X = "Apr", Y = 13.5 }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
}Positioning
Using the Position property, we can place the data label either Inside or Outside the 3D Circular Chart.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").DataLabel(dl => dl.Visible(true).Position(Syncfusion.EJ2.Charts.CircularChart3DLabelPosition.Outside)).DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Visible(false)).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;
}Data label template
The label content can be formatted using the template option. Inside the template, placeholder text ${point.x} and ${point.y can be added to display the corresponding data point’s x & y value. The data label template can be set using the Template property.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").DataLabel(dl => dl.Visible(true).Name("Text")
.Template("<div id='templateWrap' style='background-color:#bd18f9;border-radius: 3px; float: right;padding: 2px;line-height: 20px;text-align: center;'>"+ "<img src='https://ej2.syncfusion.com/demos/src/chart/images/sunny.png' />" + "<div style='color:white; font-family:Roboto; font-style: medium; fontp-size:14px;float: right;padding: 2px;line-height: 20px;text-align: center;padding-right:6px'><span>${point.y}</span></div></div>")).DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Visible(false)).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 13, Text = "Jan: 13" },
new CircularChartData { X = "Feb", Y = 13, Text = "Feb: 13" },
new CircularChartData { X = "Mar", Y = 17, Text = "Mar: 17" },
new CircularChartData { X = "Apr", Y = 13.5, Text = "Apr: 13.5" }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
public string Text;
}Connector line
The connector line will be visible when the data label is placed Outside the chart. It can be customized using properties such as Color, Width, Length, and DashArray within the ConnectorStyle property.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").DataLabel(dl => dl.Visible(true).Name("Text").Position(Syncfusion.EJ2.Charts.CircularChart3DLabelPosition.Outside)
.ConnectorStyle(cs => cs.Length("50px").Width(2).Color("#f4429e").DashArray("5,3"))).DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Visible(false)).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 13, Text = "Jan: 13" },
new CircularChartData { X = "Feb", Y = 13, Text = "Feb: 13" },
new CircularChartData { X = "Mar", Y = 17, Text = "Mar: 17" },
new CircularChartData { X = "Apr", Y = 13.5, Text = "Apr: 13.5" }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
public string Text;
}Text mapping
Text from the data source can be mapped using the Name property within the data label.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").DataLabel(dl => dl.Visible(true).Name("Text")).DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Visible(false)).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 3, Text = "January" },
new CircularChartData { X = "Feb", Y = 3.5, Text = "February" },
new CircularChartData { X = "Mar", Y = 7, Text = "March" },
new CircularChartData { X = "Apr", Y = 13.5, Text = "April" }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
public string Text;
}Format
The data label for the 3D Circular Chart can be formatted using the Format property. You can utilize global formatting options such as ‘n’, ‘p’, and ‘c’.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").DataLabel(dl => dl.Visible(true).Format("n2")).DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Visible(false)).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 = 7 },
new CircularChartData { X = "Apr", Y = 13 }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
}| Value | Format | Resultant Value | Description |
|---|---|---|---|
| 1000 | n1 | 1000.0 | The number is rounded to 1 decimal place. |
| 1000 | n2 | 1000.00 | The number is rounded to 2 decimal places. |
| 1000 | n3 | 1000.000 | The number is rounded to 3 decimal place. |
| 0.01 | p1 | 1.0% | The number is converted to percentage with 1 decimal place. |
| 0.01 | p2 | 1.00% | The number is converted to percentage with 2 decimal place. |
| 0.01 | p3 | 1.000% | The number is converted to percentage with 3 decimal place. |
| 1000 | c1 | $1000.0 | The currency symbol is appended to number and number is rounded to 1 decimal place. |
| 1000 | c2 | $1000.00 | The currency symbol is appended to number and number is rounded to 2 decimal place. |
Customization
Individual text for the data points in the 3D Circular Chart can be customized using the TextRender event.
@Html.EJS().CircularChart3D("container").Tilt(-45).TextRender("textRender").Series(series =>
{
series.XName("X").YName("Y").DataLabel(dl => dl.Visible(true).Name("Text").Position(Syncfusion.EJ2.Charts.CircularChart3DLabelPosition.Outside)).DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Visible(false)).Render()
<script>
var textRender = function(args) {
if (args.text.indexOf('Mar') > -1) {
args.color = 'red';
args.border.width = 1;
}
}
</script>public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 13, Text = "Jan: 13" },
new CircularChartData { X = "Feb", Y = 13, Text = "Feb: 13" },
new CircularChartData { X = "Mar", Y = 17, Text = "Mar: 17" },
new CircularChartData { X = "Apr", Y = 13.5, Text = "Apr: 13.5" }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
public string Text;
}Using textRender event
You can customize the data label of a pie chart using the TextRender event as follows to show the percentage.
@Html.EJS().CircularChart3D("container").Tilt(-45).TextRender("textRender").Series(series =>
{
series.XName("X").YName("Y").DataLabel(dl => dl.Visible(true)).DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Visible(false)).Render()
<script>
var textRender = function(args) {
args.text = args.point.percentage + "%";
}
</script>public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 13 },
new CircularChartData { X = "Feb", Y = 13.5 },
new CircularChartData { X = "Mar", Y = 7 },
new CircularChartData { X = "Apr", Y = 13.5 }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
}Using template
You can display the percentage values in the data label of a pie chart using the Template option.
@Html.EJS().CircularChart3D("container").Tilt(-45).Series(series =>
{
series.XName("X").YName("Y").DataLabel(dl => dl.Visible(true).Template("<div id='dataLabelTemplate'>${point.percentage}%</div>")).DataSource(ViewBag.dataSource).Add();
}
).LegendSettings(leg => leg.Visible(false)).Render()public IActionResult Index()
{
List<CircularChartData> circularData = new List<CircularChartData>
{
new CircularChartData { X = "Jan", Y = 13 },
new CircularChartData { X = "Feb", Y = 13.5 },
new CircularChartData { X = "Mar", Y = 7 },
new CircularChartData { X = "Apr", Y = 13.5 }
};
ViewBag.dataSource = circularData;
return View();
}
public class CircularChartData
{
public string X;
public double Y;
}