Search results

Data Labels

Data label can be added to a chart series by enabling the visible option in the dataLabel. By default, the labels will arrange smartly without overlapping.

tagHelper
datalabel.cs
<ejs-chart id="container" width="60%">
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x" yName="y"
                      type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column">
             <e-series-marker>
                 <e-series-datalabel visible="true"></e-series-datalabel>
             </e-series-marker>
            </e-series>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            List<Data> chartData = new List<Data>
            {
           new Data{ x= "Jan", y= 3,   fill= "#498fff", text= "January" },
           new Data{ x= "Feb", y= 3.5, fill= "#ffa060", text= "February" },
           new Data{ x= "Mar", y= 7,   fill= "#ff68b6", text= "March" },
           new Data{ x= "Apr", y= 13.5,fill= "#81e2a1", text= "April" }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class Data
        {
            public string x;
            public double y;
            public string fill;
            public string text;
        }

Position

Using position property, you can place the label either on Top, Middle,Bottom or Outer (outer is applicable for column and bar type series).

tagHelper
position.cs
<ejs-chart id="container" width="60%">
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x" yName="y"
                      type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column">
             <e-series-marker>
                 <e-series-datalabel visible="true" position="Middle"></e-series-datalabel>
             </e-series-marker>
            </e-series>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            List<Data> chartData = new List<Data>
            {
           new Data{ x= "Jan", y= 3,   fill= "#498fff", text= "January" },
           new Data{ x= "Feb", y= 3.5, fill= "#ffa060", text= "February" },
           new Data{ x= "Mar", y= 7,   fill= "#ff68b6", text= "March" },
           new Data{ x= "Apr", y= 13.5,fill= "#81e2a1", text= "April" }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class Data
        {
            public string x;
            public double y;
            public string fill;
            public string text;
        }

Note: The position Outer is applicable for column and bar type series.

Datalabel template

Label content can be formatted by using the template option. Inside the template, you can add the placeholder text ${point.x} and ${point.y} to display corresponding data points x & y value. Using template property, you can set data label template in chart.

tagHelper
template.cs
<ejs-chart id="container" width="60%">
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x" yName="y"
                      type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column">
             <e-series-marker>
                 <e-series-datalabel visible="true" position="Middle"
                  template="#template"></e-series-datalabel>
             </e-series-marker>
            </e-series>
        </e-series-collection>
    </ejs-chart>
<script id="template">
    <div style="background:#f5f5f5; border: 1px solid black; padding: 3px 3px 3px 3px">
        <div>${point.x}</div>
        <div>${point.y}</div>
    </div>
</script>
public ActionResult Index()
        {
            List<Data> chartData = new List<Data>
            {
           new Data{ x= "Jan", y= 3,   fill= "#498fff", text= "January" },
           new Data{ x= "Feb", y= 3.5, fill= "#ffa060", text= "February" },
           new Data{ x= "Mar", y= 7,   fill= "#ff68b6", text= "March" },
           new Data{ x= "Apr", y= 13.5,fill= "#81e2a1", text= "April" }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class Data
        {
            public string x;
            public double y;
            public string fill;
            public string text;
        }

Text Mapping

Text from the data source can be mapped using name property.

tagHelper
mapping.cs
<ejs-chart id="container" width="60%">
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x" yName="y"
                      type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column">
             <e-series-marker>
                 <e-series-datalabel visible="true" name="text"></e-series-datalabel>
             </e-series-marker>
            </e-series>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            List<Data> chartData = new List<Data>
            {
           new Data{ x= "Jan", y= 3,   fill= "#498fff", text= "January" },
           new Data{ x= "Feb", y= 3.5, fill= "#ffa060", text= "February" },
           new Data{ x= "Mar", y= 7,   fill= "#ff68b6", text= "March" },
           new Data{ x= "Apr", y= 13.5,fill= "#81e2a1", text= "April" }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class Data
        {
            public string x;
            public double y;
            public string fill;
            public string text;
        }

Margin

margin for data label can be applied to using left, right, bottom and top properties.

tagHelper
margin.cs
@{
    var border = new { width = 2, color = "red" };
    var margin = new { left = 15, right = 15, bottom = 15, top = 15 };
 }
 <ejs-chart id="container" width="60%">
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x" yName="y"
                      type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column">
             <e-series-marker>
                 <e-series-datalabel visible="true" name="text" border="border" margin="margin"></e-series-datalabel>
             </e-series-marker>
            </e-series>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            List<Data> chartData = new List<Data>
            {
           new Data{ x= "Jan", y= 3,   fill= "#498fff", text= "January" },
           new Data{ x= "Feb", y= 3.5, fill= "#ffa060", text= "February" },
           new Data{ x= "Mar", y= 7,   fill= "#ff68b6", text= "March" },
           new Data{ x= "Apr", y= 13.5,fill= "#81e2a1", text= "April" }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class Data
        {
            public string x;
            public double y;
            public string fill;
            public string text;
        }

Customization

stroke and border of data label can be customized using fill and border properties. Rounded corners can be customized using rx and ry properties.

tagHelper
custom.cs
@{
    var border = new { width = 2, color = "red" };
 }
 <ejs-chart id="container" width="60%">
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x" yName="y"
                      type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column">
             <e-series-marker>
                 <e-series-datalabel visible="true" name="text" border="border" rx="10" ry="10"></e-series-datalabel>
             </e-series-marker>
            </e-series>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            List<Data> chartData = new List<Data>
            {
           new Data{ x= "Jan", y= 3,   fill= "#498fff", text= "January" },
           new Data{ x= "Feb", y= 3.5, fill= "#ffa060", text= "February" },
           new Data{ x= "Mar", y= 7,   fill= "#ff68b6", text= "March" },
           new Data{ x= "Apr", y= 13.5,fill= "#81e2a1", text= "April" }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class Data
        {
            public string x;
            public double y;
            public string fill;
            public string text;
        }

Note: rx and ry properties requires border values not to be null.

Customizing Specific Point

You can also customize the specific marker and label using pointRender and textRender event. pointRender event allows you to change the shape, color and border for a point, whereas the textRender event allows you to change the text for the point.

tagHelper
custom-point.cs
<ejs-chart id="container" width="60%" pointRender="pointRender" textRender="textRender">
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x" yName="y"
                      type="@Syncfusion.EJ2.Charts.ChartSeriesType.Column">
             <e-series-marker>
                 <e-series-datalabel visible="true"></e-series-datalabel>
             </e-series-marker>
            </e-series>
        </e-series-collection>
    </ejs-chart>
<script>
    pointRender=function(args) {
        if (args.point.index === 2) {
            args.fill = 'red'
        }
    },
    textRender = function (args) {
            if (args.point.index === 2) {
                args.text = 'Maximum Temperature';
                args.color = 'red';
            }
            else {
                args.cancel = true;
            }
        }
</script>
public ActionResult Index()
        {
            List<Data> chartData = new List<Data>
            {
           new Data{ x= "Jan", y= 3,   fill= "#498fff", text= "January" },
           new Data{ x= "Feb", y= 3.5, fill= "#ffa060", text= "February" },
           new Data{ x= "Mar", y= 7,   fill= "#ff68b6", text= "March" },
           new Data{ x= "Apr", y= 13.5,fill= "#81e2a1", text= "April" }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class Data
        {
            public string x;
            public double y;
            public string fill;
            public string text;
        }