|
| 1 | +--- |
| 2 | +title: How to set rounded corner for chart in Excel document | Syncfusion |
| 3 | +description: Code example to set rounded corner for chart in Excel document using Syncfusion .NET Excel library (XlsIO). |
| 4 | +platform: file-formats |
| 5 | +control: XlsIO |
| 6 | +documentation: UG |
| 7 | +--- |
| 8 | + |
| 9 | +# How to set rounded corner for chart in Excel document? |
| 10 | + |
| 11 | +The following code snippet shows how to set rounded corner for chart in Excel document. |
| 12 | + |
| 13 | +{% tabs %} |
| 14 | +{% highlight c# tabtitle="C# [Cross-platform]" %} |
| 15 | +using (ExcelEngine excelEngine = new ExcelEngine()) |
| 16 | +{ |
| 17 | + IApplication application = excelEngine.Excel; |
| 18 | + application.DefaultVersion = ExcelVersion.Xlsx; |
| 19 | + IWorkbook workbook = application.Workbooks.Create(1); |
| 20 | + IWorksheet sheet = workbook.Worksheets[0]; |
| 21 | + |
| 22 | + object[] xValues = new object[] { "Total Income", "Expenses", "Profit" }; |
| 23 | + object[] yValues = new object[] { 2000, 1000, 1500 }; |
| 24 | + |
| 25 | + //Adding series and values |
| 26 | + IChartShape chart = sheet.Charts.Add(); |
| 27 | + IChartSerie serie = chart.Series.Add(ExcelChartType.Column_Clustered); |
| 28 | + |
| 29 | + //set the rounded border for the chart |
| 30 | + chart.ChartArea.IsBorderCornersRound = true; |
| 31 | + |
| 32 | + //sets the top row of the chart |
| 33 | + chart.TopRow = 5; |
| 34 | + chart.BottomRow = 20; |
| 35 | + chart.LeftColumn = 5; |
| 36 | + chart.RightColumn = 13; |
| 37 | + |
| 38 | + //Enters the X and Y values directly |
| 39 | + serie.EnteredDirectlyValues = yValues; |
| 40 | + serie.EnteredDirectlyCategoryLabels = xValues; |
| 41 | + |
| 42 | + //Saving the workbook as stream |
| 43 | + FileStream stream = new FileStream("Chart.xlsx", FileMode.Create, FileAccess.ReadWrite); |
| 44 | + workbook.SaveAs(stream); |
| 45 | + stream.Dispose(); |
| 46 | +} |
| 47 | +{% endhighlight %} |
| 48 | + |
| 49 | +{% highlight c# tabtitle="C# [Windows-specific]" %} |
| 50 | +using (ExcelEngine excelEngine = new ExcelEngine()) |
| 51 | +{ |
| 52 | + IApplication application = excelEngine.Excel; |
| 53 | + application.DefaultVersion = ExcelVersion.Xlsx; |
| 54 | + IWorkbook workbook = application.Workbooks.Create(1); |
| 55 | + IWorksheet sheet = workbook.Worksheets[0]; |
| 56 | + |
| 57 | + object[] xValues = new object[] { "Total Income", "Expenses", "Profit" }; |
| 58 | + object[] yValues = new object[] { 2000, 1000, 1500 }; |
| 59 | + |
| 60 | + //Adding series and values |
| 61 | + IChartShape chart = sheet.Charts.Add(); |
| 62 | + IChartSerie serie = chart.Series.Add(ExcelChartType.Column_Clustered); |
| 63 | + |
| 64 | + //set the rounded border for the chart |
| 65 | + chart.ChartArea.IsBorderCornersRound = true; |
| 66 | + |
| 67 | + //sets the top row of the chart |
| 68 | + chart.TopRow = 5; |
| 69 | + chart.BottomRow = 20; |
| 70 | + chart.LeftColumn = 5; |
| 71 | + chart.RightColumn = 13; |
| 72 | + |
| 73 | + //Enters the X and Y values directly |
| 74 | + serie.EnteredDirectlyValues = yValues; |
| 75 | + serie.EnteredDirectlyCategoryLabels = xValues; |
| 76 | + |
| 77 | + //Saving the workbook |
| 78 | + workbook.SaveAs("Chart.xlsx"); |
| 79 | + stream.Dispose(); |
| 80 | +} |
| 81 | +{% endhighlight %} |
| 82 | + |
| 83 | +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} |
| 84 | +Using excelEngine As ExcelEngine = New ExcelEngine() |
| 85 | + Dim Application As IApplication = excelEngine.Excel |
| 86 | + Application.DefaultVersion = ExcelVersion.Xlsx |
| 87 | + Dim workbook As IWorkbook = Application.Workbooks.Create(1) |
| 88 | + Dim sheet As IWorksheet = workbook.Worksheets(0) |
| 89 | + |
| 90 | + Dim xValues As Object() = New Object() {"Total Income", "Expenses", "Profit"} |
| 91 | + Dim yValues As Object() = New Object() {2000, 1000, 1000} |
| 92 | + |
| 93 | + 'Adding series And values |
| 94 | + Dim chart As IChartShape = sheet.Charts.Add() |
| 95 | + Dim serie As IChartSerie = chart.Series.Add(ExcelChartType.Column_Clustered) |
| 96 | + |
| 97 | + 'set the rounded border for the chart |
| 98 | + chart.ChartArea.IsBorderCornersRound = True |
| 99 | + |
| 100 | + 'sets the top row of the chart |
| 101 | + chart.TopRow = 5 |
| 102 | + chart.BottomRow = 20 |
| 103 | + chart.LeftColumn = 5 |
| 104 | + chart.RightColumn = 13 |
| 105 | + |
| 106 | + 'Enters the X And Y values directly |
| 107 | + serie.EnteredDirectlyValues = yValues |
| 108 | + serie.EnteredDirectlyCategoryLabels = xValues |
| 109 | + |
| 110 | + 'Saving the workbook as stream |
| 111 | + Dim Stream As FileStream = New FileStream("Chart.xlsx", FileMode.Create, FileAccess.ReadWrite) |
| 112 | + workbook.SaveAs(Stream) |
| 113 | + Stream.Dispose() |
| 114 | +End Using |
| 115 | +{% endhighlight %} |
| 116 | +{% endtabs %} |
| 117 | + |
| 118 | +## See Also |
| 119 | + |
| 120 | +* [How to change the border style for chart series](https://help.syncfusion.com/file-formats/xlsio/working-with-charts#border-style-for-chart-series) |
| 121 | +* [How to explode a Pie Chart](https://help.syncfusion.com/file-formats/xlsio/working-with-charts#explode-a-pie-chart) |
| 122 | +* [How to add picture to the chart and assign hyperlink](https://help.syncfusion.com/file-formats/xlsio/working-with-charts#add-picture-to-chart-and-assign-hyperlink) |
| 123 | +* [How to customizing chart and chart elements](https://help.syncfusion.com/file-formats/xlsio/working-with-charts#customizing-chart-and-chart-elements) |
| 124 | +* [How to add data label to the chart](https://help.syncfusion.com/file-formats/xlsio/working-with-charts#add-datatable-to-chart) |
0 commit comments