Show / Hide Table of Contents

Set Data Label

Set data labels on a series, configure to show category name, series name and legend key. Set the data label's font size to 8.

Output: DataLabelText.xlsx

var workbook = new Workbook();
var worksheet = workbook.Worksheets[0];

worksheet.GetRange("J1:L1").SetValue(new[] { "Series 1", "Series 2", "Series 3" });
worksheet.GetRange("I2:I5").SetValue(new[] { "Point 1", "Point 2", "Point 3", "Point 4" });
worksheet.GetRange("J2:J5").SetValue(new[] { 2, 4, 6, 8 });
worksheet.GetRange("K2:K5").SetValue(new[] { 4, 3, 2, 1 });
worksheet.GetRange("L2:L5").SetValue(new[] { 2, 1, -1, -2 });

var chart1 = worksheet.Charts.Add<BarChart>("A1");
chart1.ChartType = ChartType.Column;
chart1.Size.HeightInches = 3;
chart1.Size.WidthInches = 5;
chart1.DataSource = "Sheet1!$I$1:$L$5";

chart1.DataSeries[0].DataLabels = new DataLabels();
chart1.DataSeries[0].DataLabels.ShowCategoryName = true;
chart1.DataSeries[0].DataLabels.ShowSeriesName = true;
chart1.DataSeries[0].DataLabels.ShowLegendKey = true;
chart1.DataSeries[0].DataLabels.FormattedText.Font.Size = 8;

workbook.SaveAs("DataLabelText.xlsx");
Back to top Generated by DocFX