Search results

Data Labels

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

datalabel.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Width="60%">
        <ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
  
        <ChartSeriesCollection> 
            <ChartSeries DataSource="@WeatherReports" XName="X" YName="Y" Type="ChartSeriesType.Column"> 
                <ChartMarker> 
                    <ChartDataLabel Visible="true"></ChartDataLabel> 
                </ChartMarker> 
            </ChartSeries> 
        </ChartSeriesCollection> 
</EjsChart> 

@code{
    public class Data
    {
        public string X;
        public double Y;
    }
    public List<Data> WeatherReports = new List<Data> 
    {
        new Data{ X= "Jan", Y= 3 },
        new Data{ X= "Feb", Y= 3.5 },
        new Data{ X= "Mar", Y= 7 },
        new Data{ X= "Apr", Y= 13.5 }
    };
}

Data Labels

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).

position.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Width="60%">
        <ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
  
        <ChartSeriesCollection>
            <ChartSeries DataSource="@WeatherReports" XName="X" YName="Y" Type="ChartSeriesType.Column">
                <ChartMarker>
                    <ChartDataLabel Visible="true" Position="LabelPosition.Middle"></ChartDataLabel>
                </ChartMarker>
            </ChartSeries>
        </ChartSeriesCollection>
</EjsChart>

@code{
    public class Data
    {
        public string X;
        public double Y;
    }
    public List<Data> WeatherReports = new List<Data> 
    {
        new Data{ X= "Jan", Y= 3 },
        new Data{ X= "Feb", Y= 3.5 },
        new Data{ X= "Mar", Y= 7 },
        new Data{ X= "Apr", Y= 13.5 }
    };
}

Position

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

Data label 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.

Text Mapping

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

mapping.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Width="60%">
        <ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis> 
  
        <ChartSeriesCollection> 
            <ChartSeries DataSource="@WeatherReports" XName="X" YName="Y" Type="ChartSeriesType.Column"> 
                <ChartMarker> 
                    <ChartDataLabel Visible="true" Name="Text"></ChartDataLabel> 
                </ChartMarker> 
            </ChartSeries>  
        </ChartSeriesCollection> 
</EjsChart> 
 
@code{
    public class Data
    {
        public string X;
        public double Y;
        public string Text;
    }

    public List<Data> WeatherReports = new List<Data> {
           new Data{ X= "Jan", Y= 3, Text= "January" },
           new Data{ X= "Feb", Y= 3.5, Text= "February" },
           new Data{ X= "Mar", Y= 7, Text= "March" },
           new Data{ X= "Apr", Y= 13.5, Text= "April" }
        };
}

Text Mapping

Margin

Margin for data label can be applied to using Left, Right, Bottom and Top properties.

margin.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Width="60%">
        <ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.Category">
        </ChartPrimaryXAxis>
  
        <ChartSeriesCollection>
            <ChartSeries DataSource="@WeatherReports" XName="X" YName="Y" Type="ChartSeriesType.Column">
                <ChartMarker>
                    <ChartDataLabel Visible="true" Name="Text">
                        <ChartDataLabelBorder Width="2" Color="red"></ChartDataLabelBorder>
                        <ChartDataLabelMargin Left="15" Right="15" Top="15" Bottom="15"></ChartDataLabelMargin>
                    </ChartDataLabel>
                </ChartMarker>
            </ChartSeries>
        </ChartSeriesCollection>
</EjsChart>

@code{
    public class Data
    {
        public string X;
        public double Y;
        public string Text;
    }

    public List<Data> WeatherReports = new List<Data> {
           new Data{ X= "Jan", Y= 3, Text= "January" },
           new Data{ X= "Feb", Y= 3.5, Text= "February" },
           new Data{ X= "Mar", Y= 7, Text= "March" },
           new Data{ X= "Apr", Y= 13.5, Text= "April" }
        };
}

Margin

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.

custom.razor
@using Syncfusion.EJ2.Blazor.Charts

<EjsChart Width="60%">
        <ChartPrimaryXAxis ValueType="Syncfusion.EJ2.Blazor.Charts.ValueType.Category">
        </ChartPrimaryXAxis>
  
        <ChartSeriesCollection>
            <ChartSeries DataSource="@WeatherReports" XName="X" YName="Y" Type="ChartSeriesType.Line">
                <ChartMarker>
                    <ChartDataLabel Visible="true" Name="Text" Rx="10" Ry="10">
                        <ChartDataLabelBorder Width="2" Color="red"></ChartDataLabelBorder>
                    </ChartDataLabel>
                </ChartMarker>
            </ChartSeries>
        </ChartSeriesCollection>
</EjsChart>

@code{
    public class Data
    {
        public string X;
        public double Y;
        public string Text;
    }

    public List<Data> WeatherReports = new List<Data> {
           new Data{ X= "Jan", Y= 3, Text= "January" },
           new Data{ X= "Feb", Y= 3.5, Text= "February" },
           new Data{ X= "Mar", Y= 7, Text= "March" },
           new Data{ X= "Apr", Y= 13.5, Text= "April" }
        };
}

Customization

Note: Rx and Ry properties requires Border values not to be null.

See Also