2D Chart for WinForms | ComponentOne
Chart for WinForms Task-Based Help / Adding a Data Label on Top of Each Bar
In This Topic
    Adding a Data Label on Top of Each Bar
    In This Topic

    To add a data label on top of each bar, use the following code:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim sc As ChartDataSeriesCollection =        
    C1Chart1.ChartGroups(0).ChartData.SeriesList        
    Dim i As Integer        
    For i = 0 To sc.Count - 1        
    With sc(i).DataLabel        
            .Visible = True        
            .Compass = LabelCompassEnum.North
            .Text = "{#YVAL}"        
    End With        
    Next
    

    To write code in C#

    C#
    Copy Code
    ChartDataSeriesCollection sc = c1Chart1.ChartGroups[0].ChartData.SeriesList;
    int i = 0;
    for (i = 0; i <= sc.Count - 1; i++)
    {
        var _with1 = sc[i].DataLabel;
        _with1.Visible = true;
        _with1.Compass = LabelCompassEnum.North;
        _with1.Text = "{#YVAL}";
    }
    
    See Also