How to change data point label color of a Waterfall chart?

8 Dec 20233 minutes to read

The following code snippet shows how to change data point label color of a Waterfall chart.

using (ExcelEngine excelEngine = new ExcelEngine())
{
  IApplication application = excelEngine.Excel;
  application.DefaultVersion = ExcelVersion.Excel2016;
  FileStream inputStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
  IWorkbook workbook = application.Workbooks.Open(inputStream,ExcelOpenType.Automatic);
  IWorksheet sheet = workbook.Worksheets[0];

  //Accessing first chart in the sheet
  IChartShape chart = sheet.Charts[0];

  //Changing first data point label color
  chart.Series[0].DataPoints[0].DataLabels.IsValue = true;
  chart.Series[0].DataPoints[0].DataLabels.RGBColor = Color.Green;

  //Saving the workbook as stream
  FileStream stream = new FileStream("Waterfall.xlsx", FileMode.Create, FileAccess.ReadWrite);
  workbook.SaveAs(stream);
  stream.Dispose();
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
  IApplication application = excelEngine.Excel;
  application.DefaultVersion = ExcelVersion.Excel2016;
  IWorkbook workbook = application.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic);
  IWorksheet sheet = workbook.Worksheets[0];

  //Accessing first chart in the sheet
  IChartShape chart = sheet.Charts[0];

  //Changing first data point label color
  chart.Series[0].DataPoints[0].DataLabels.IsValue = true;
  chart.Series[0].DataPoints[0].DataLabels.RGBColor = Color.Green;

  workbook.SaveAs("Waterfall.xlsx");
}
Using excelEngine As ExcelEngine = New ExcelEngine()
  Dim application As IApplication = excelEngine.Excel
  application.DefaultVersion = ExcelVersion.Excel2016
  Dim workbook As IWorkbook = application.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic)
  Dim sheet As IWorksheet = workbook.Worksheets(0)

  'Create a chart
  Dim chart As IChartShape = sheet.Charts(0)

  'Changing first data point label color
  chart.Series(0).DataPoints(0).DataLabels.IsValue = true
  chart.Series(0).DataPoints(0).DataLabels.RGBColor = Color.Green

  workbook.SaveAs("Waterfall.xlsx")
End Using

See Also