Articles in this section
Category / Section

How to position and re-size a plot area of chart using WinForms XlsIO?

2 mins read

The position and size of a chart’s plot area can be edited by setting ManualLayoutOption instead of referring Layout option. Please refer the below code snippet to edit the position and re-size a chart’s plot area using XlsIO

C#

             //Step 1 : Instantiate the spreadsheet creation engine.
            ExcelEngine excelEngine = new ExcelEngine();
            //Step 2 : Instantiate the excel application object.
            IApplication application = excelEngine.Excel;
 
            string inputPath = GetFullTemplatePath("Sample.xlsx");
 
            IWorkbook workbook = application.Workbooks.Open(inputPath, ExcelOpenType.Automatic);
 
            //The first worksheet object in the worksheets collection is accessed.
            IWorksheet worksheet = workbook.Worksheets[0];
            IChartShape chart = worksheet.Charts.Add();
            IChartSerie serie = chart.Series.Add("Pie Chart");
            serie.SerieType = ExcelChartType.Pie;
            serie.Values = worksheet.Range["C1:C5"];
            serie.CategoryLabels = worksheet.Range["B1:B5"];
            chart.PlotArea.Layout.ManualLayout.LayoutTarget = LayoutTargets.outer;
            chart.PlotArea.Layout.ManualLayout.LeftMode = LayoutModes.edge;
            chart.PlotArea.Layout.ManualLayout.TopMode = LayoutModes.edge;
            chart.PlotArea.Layout.ManualLayout.Height = 0.7;
            chart.PlotArea.Layout.ManualLayout.Width = 0.6;
            chart.PlotArea.Layout.ManualLayout.Left = 0.1;
            chart.PlotArea.Layout.ManualLayout.Top = 0.2;

VB

            'Step 1 : Instantiate the spreadsheet creation engine.
            Dim excelEngine As ExcelEngine = New ExcelEngine()
            'Step 2 : Instantiate the excel application object.
            Dim application As IApplication = excelEngine.Excel
 
            Dim inputPath As String = GetFullTemplatePath("Sample.xlsx")
 
            Dim workbook As IWorkbook = application.Workbooks.Open(inputPath, ExcelOpenType.Automatic)
 
            'The first worksheet object in the worksheets collection is accessed.
            Dim worksheet As IWorksheet = workbook.Worksheets(0)
            Dim chart As IChartShape = worksheet.Charts.Add()
            Dim serie As IChartSerie = chart.Series.Add("Pie Chart")
            serie.SerieType = ExcelChartType.Pie
            serie.Values = worksheet.Range("C1:C5")
            serie.CategoryLabels = worksheet.Range("B1:B5")
            chart.PlotArea.Lay.ManualLay.LayoutTarget = LayoutTargets.outer
            chart.PlotArea.Lay.ManualLay.LeftMode = LayoutModes.edge
            chart.PlotArea.Lay.ManualLay.TopMode = LayoutModes.edge
            chart.PlotArea.Lay.ManualLay.Height = 0.7
            chart.PlotArea.Lay.ManualLay.Width = 0.6
            chart.PlotArea.Lay.ManualLay.Left = 0.1
            chart.PlotArea.Lay.ManualLay.Top = 0.2

 

The sample illustrating this behavior can be downloaded here.

Conclusion

I hope you enjoyed learning about how to position and re-size a plot area of chart using WinForms XlsIO.

You can refer to our WinForms XIsIO feature tour page to know about its other groundbreaking feature representations documentation and how to quickly get started for configuration specifications.  You can also explore our WinForms XIsIO example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied