Having trouble getting help?
Contact Support
Contact Support
How to set rounded corner for chart in Excel document?
8 Dec 20235 minutes to read
The following code snippet shows how to set rounded corner for chart in Excel document.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
object[] xValues = new object[] { "Total Income", "Expenses", "Profit" };
object[] yValues = new object[] { 2000, 1000, 1500 };
//Adding series and values
IChartShape chart = sheet.Charts.Add();
IChartSerie serie = chart.Series.Add(ExcelChartType.Column_Clustered);
//set the rounded border for the chart
chart.ChartArea.IsBorderCornersRound = true;
//sets the top row of the chart
chart.TopRow = 5;
chart.BottomRow = 20;
chart.LeftColumn = 5;
chart.RightColumn = 13;
//Enters the X and Y values directly
serie.EnteredDirectlyValues = yValues;
serie.EnteredDirectlyCategoryLabels = xValues;
//Saving the workbook as stream
FileStream stream = new FileStream("Chart.xlsx", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(stream);
stream.Dispose();
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
object[] xValues = new object[] { "Total Income", "Expenses", "Profit" };
object[] yValues = new object[] { 2000, 1000, 1500 };
//Adding series and values
IChartShape chart = sheet.Charts.Add();
IChartSerie serie = chart.Series.Add(ExcelChartType.Column_Clustered);
//set the rounded border for the chart
chart.ChartArea.IsBorderCornersRound = true;
//sets the top row of the chart
chart.TopRow = 5;
chart.BottomRow = 20;
chart.LeftColumn = 5;
chart.RightColumn = 13;
//Enters the X and Y values directly
serie.EnteredDirectlyValues = yValues;
serie.EnteredDirectlyCategoryLabels = xValues;
//Saving the workbook
workbook.SaveAs("Chart.xlsx");
stream.Dispose();
}
Using excelEngine As ExcelEngine = New ExcelEngine()
Dim Application As IApplication = excelEngine.Excel
Application.DefaultVersion = ExcelVersion.Xlsx
Dim workbook As IWorkbook = Application.Workbooks.Create(1)
Dim sheet As IWorksheet = workbook.Worksheets(0)
Dim xValues As Object() = New Object() {"Total Income", "Expenses", "Profit"}
Dim yValues As Object() = New Object() {2000, 1000, 1000}
'Adding series And values
Dim chart As IChartShape = sheet.Charts.Add()
Dim serie As IChartSerie = chart.Series.Add(ExcelChartType.Column_Clustered)
'set the rounded border for the chart
chart.ChartArea.IsBorderCornersRound = True
'sets the top row of the chart
chart.TopRow = 5
chart.BottomRow = 20
chart.LeftColumn = 5
chart.RightColumn = 13
'Enters the X And Y values directly
serie.EnteredDirectlyValues = yValues
serie.EnteredDirectlyCategoryLabels = xValues
'Saving the workbook as stream
Dim Stream As FileStream = New FileStream("Chart.xlsx", FileMode.Create, FileAccess.ReadWrite)
workbook.SaveAs(Stream)
Stream.Dispose()
End Using