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
- How to change the grid line color of the Excel sheet?
- How to import data table with its data type using template markers?
- How to add chart labels to scatter points?
- How to create a Chart with a discontinuous range?
- How to create a Waterfall chart?
- What are the chart data label formatting?
- What are the font settings for chart legend and data labels?