Spread WPF 18
Features / Charts / Chart Elements / Data Label
In This Topic
    Data Label
    In This Topic

    Data Labels add specific details to individual data points in a data series. They are used to ensure that users can easily understand and interpret the information plotted in a chart.

    You can get or set the data labels, change their position and color, and control whether to show the data labels in the chart using the ApplyDataLabels method of the IChart interface. It returns the members of DataLabelVisibilities enumeration.

    The following example code shows how to configure data labels in a chart.

    Copy Code
    spreadSheet1.Workbook.ActiveSheet.Cells[0, 1].Value = "Q1";
    spreadSheet1.Workbook.ActiveSheet.Cells[0, 2].Value = "Q2";
    spreadSheet1.Workbook.ActiveSheet.Cells[0, 3].Value = "Q3";
    spreadSheet1.Workbook.ActiveSheet.Cells[1, 0].Value = "Mobile Phones";
    spreadSheet1.Workbook.ActiveSheet.Cells[2, 0].Value = "Laptops";
    spreadSheet1.Workbook.ActiveSheet.Cells[3, 0].Value = "Tablets";
    for (var r = 1; r <= 3; r++)
    {
         for (var c = 1; c <= 3; c++)
         {
            Random random = new Random();
            spreadSheet1.Workbook.ActiveSheet.Cells[r, c].Value = 0 + random.Next(0, 100);
         }
    }
    spreadSheet1.Workbook.ActiveSheet.Cells["A1:D4"].Select();
    spreadSheet1.Workbook.ActiveSheet.Shapes.AddChart(GrapeCity.Spreadsheet.Charts.ChartType.ColumnClustered, 100, 150, 400, 300, true);
    spreadSheet1.Workbook.ActiveSheet.ChartObjects[0].Chart.ChartTitle.Text = "Sales Report";
    spreadSheet1.Workbook.ActiveSheet.ChartObjects[0].Chart.ApplyDataLabels(DataLabelVisibilities.Value);
    
    Copy Code
    spreadSheet1.Workbook.ActiveSheet.Cells(0, 1).Value = "Q1"
    spreadSheet1.Workbook.ActiveSheet.Cells(0, 2).Value = "Q2"
    spreadSheet1.Workbook.ActiveSheet.Cells(0, 3).Value = "Q3"
    spreadSheet1.Workbook.ActiveSheet.Cells(1, 0).Value = "Mobile Phones"
    spreadSheet1.Workbook.ActiveSheet.Cells(2, 0).Value = "Laptops"
    spreadSheet1.Workbook.ActiveSheet.Cells(3, 0).Value = "Tablets"
    For r = 1 To 3
            For c = 1 To 3
                Dim random As Random = New Random()
                spreadSheet1.Workbook.ActiveSheet.Cells(r, c).Value = 0 + random.Next(0, 100)
            Next
    Next
    spreadSheet1.Workbook.ActiveSheet.Cells("A1:D4").[Select]()
    spreadSheet1.Workbook.ActiveSheet.Shapes.AddChart(GrapeCity.Spreadsheet.Charts.ChartType.ColumnClustered, 100, 150, 400, 300, True)
    spreadSheet1.Workbook.ActiveSheet.ChartObjects(0).Chart.ChartTitle.Text = "Sales Report"
    spreadSheet1.Workbook.ActiveSheet.ChartObjects(0).Chart.ApplyDataLabels(DataLabelVisibilities.Value)