Interface IChart
Represents a chart sheet in the workbook.
Inherited Members
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.UWP.dll
Syntax
public interface IChart : ITabSheet, IParentApplication
Properties
AutoScaling
True to automatically scale the chart. otherwise False. The RightAngleAxes property must be True.
Declaration
bool AutoScaling { get; set; }
Property Value
Type |
---|
System.Boolean |
Remarks
Excel scales a 3-D chart so that it is closer in size to the equivalent 2-D chart when this property is enabled.
Examples
The following code illustrates how to set auto scaling for charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set height percentage
chart.HeightPercent = 300;
//Set auto scaling
chart.AutoScaling = true;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
BackWall
Gets the back wall of the 3D chart. Read-only.
Declaration
IChartWallOrFloor BackWall { get; }
Property Value
Type |
---|
IChartWallOrFloor |
Examples
The following code illustrates how to access IChartWallOrFloor using BackWall property and set foreground color for the chart's BackWall.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered_3D;
//Set chart wall or floor
IChartWallOrFloor wall = chart.BackWall;
//Set color
wall.Fill.FillType = ExcelFillType.SolidColor;
wall.Fill.ForeColor = System.Drawing.Color.Red;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Categories
Gets IChartCategories collection of the chart. Read-only.
Declaration
IChartCategories Categories { get; }
Property Value
Type |
---|
IChartCategories |
Remarks
Charts are plotted using X and Y axes. X axes typically have categorical scales. Categories can include string, numeric, and date values.
Examples
The following code illustrates how to access IChartCategories collection of the chart.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart categories
IChartCategories categories = chart.Categories;
//Get count
Console.WriteLine(categories.Count);
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//3
CategoryLabelLevel
Gets or sets a value referring to the source level for the category labels.
Declaration
ExcelCategoriesLabelLevel CategoryLabelLevel { get; set; }
Property Value
Type |
---|
ExcelCategoriesLabelLevel |
Examples
By default CategoryLabelLevel is set to CategoriesLabelLevelNone. Here for example, we set CategoriesLabelLevelNone to CategoryLabelLevel property to use autogenerated category labels.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set Categories level label
chart.CategoryLabelLevel = ExcelCategoriesLabelLevel.CategoriesLabelLevelNone;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
ChartArea
Gets the chart area. Read-only.
Declaration
IChartFrameFormat ChartArea { get; }
Property Value
Type |
---|
IChartFrameFormat |
Examples
The following code illustrates how to access IChartFrameFormat using ChartArea property and set foreground color for the ChartArea.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart frame format
IChartFrameFormat frameFormat = chart.ChartArea;
//Set color
frameFormat.Fill.ForeColor = System.Drawing.Color.Red;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
ChartTitle
Gets or sets the title of the chart.
Declaration
string ChartTitle { get; set; }
Property Value
Type |
---|
System.String |
Examples
The following code illustrates how to set the title for charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set title
chart.ChartTitle = "Sample Chart";
//Set position
chart.XPos = 250;
chart.YPos = 30;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
ChartTitleArea
Gets the area for chart title. Read-only.
Declaration
IChartTextArea ChartTitleArea { get; }
Property Value
Type |
---|
IChartTextArea |
Examples
To apply formats for chart title area we can use ChartTitleArea property to access IChartTextArea. Here for example, we access IChartTextArea and set Text.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart area
IChartTextArea textArea = chart.ChartTitleArea;
//Set text
textArea.Text = "Sample Chart";
textArea.Size = 20;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
ChartType
Gets or sets the chart type.
Declaration
ExcelChartType ChartType { get; set; }
Property Value
Type |
---|
ExcelChartType |
Examples
By default the ChartType is set to Column_Clustered. Here for example, we set Pyramid_Stacked to ChartType property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = workbook.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart type
chart.ChartType = ExcelChartType.Pyramid_Stacked;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
DataRange
Gets or sets the data range for the chart series.
Declaration
IRange DataRange { get; set; }
Property Value
Type |
---|
IRange |
Remarks
If we want to give data for the chart series directly then we can use EnteredDirectlyCategoryLabels and EnteredDirectlyValues properties. To know more about giving data directly to series refer Creating a Chart from directly entered Values.
Examples
The following code illustrates how to set the data range for the chart.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = workbook.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
DataTable
Gets the IChartDataTable of the chart. Read-only.
Declaration
IChartDataTable DataTable { get; }
Property Value
Type |
---|
IChartDataTable |
Examples
By default the visibility of data table is set to "false". Here for example, we set HasDataTable to "true" to enable data table and set HasBorders to "false" to hide the borders of data table.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set Chart data table
chart.HasDataTable = true;
IChartDataTable dataTable = chart.DataTable;
//Set border
dataTable.HasBorders = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
DepthPercent
Gets or sets the depth of a 3D chart as a percentage of the chart width (20 - 2000 percent).
Declaration
int DepthPercent { get; set; }
Property Value
Type |
---|
System.Int32 |
Examples
The following code illustrates how to set DepthPercent to a Column 3D chart.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set Chart depth percent
chart.DepthPercent = 300;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
DisplayBlanksAs
Gets or sets a value indicating how the blank cells are plotted on chart.
Declaration
ExcelChartPlotEmpty DisplayBlanksAs { get; set; }
Property Value
Type |
---|
ExcelChartPlotEmpty |
Examples
If cells within the chart's DataRange has no data then those are not plotted in charts. Because by default the DisplayBlanksAs is set to NotPlotted. Here for example, we set Zero to DisplayBlanksAs property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered_3D;
//Set display as
chart.DisplayBlanksAs = ExcelChartPlotEmpty.Zero;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Elevation
Gets or sets the elevation of the 3-D chart view, in degrees (-90 to +90 degrees).
Declaration
int Elevation { get; set; }
Property Value
Type |
---|
System.Int32 |
Remarks
The chart elevation is the height at which you view the chart, in degrees. The default is 15 for most chart types. The value of this property must be between -90 and 90, except for 3-D bar charts, where it must be between 0 and 44.
Examples
The following code illustrates how to set Elevation for 3-D charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set Chart elevation
chart.Elevation = 50;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Floor
Gets the floor of the 3D chart. Read-only.
Declaration
IChartWallOrFloor Floor { get; }
Property Value
Type |
---|
IChartWallOrFloor |
Examples
The following code illustrates how to access IChartWallOrFloor using Floor property and set foreground color for the chart's Floor.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered_3D;
//Set chart wall or floor
IChartWallOrFloor wall = chart.Floor;
//Set color
wall.Fill.FillType = ExcelFillType.SolidColor;
wall.Fill.ForeColor = System.Drawing.Color.Red;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
GapDepth
Gets or sets the distance between data series in a 3D chart, as a percentage of marker width ( 0 - 500 ).
Declaration
int GapDepth { get; set; }
Property Value
Type |
---|
System.Int32 |
Examples
The following code illustrates how to set GapDepth to a Column 3D chart.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set gap depth
chart.GapDepth = 450;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
HasDataTable
True if the chart has data table. otherwise False.
Declaration
bool HasDataTable { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how data table can be set for charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set Chart data table
chart.HasDataTable = true;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
HasLegend
True if the chart has a legend object. otherwise False.
Declaration
bool HasLegend { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how to set HasLegend property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set hasLegend
chart.HasLegend = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
HasPlotArea
Gets or sets a boolean value indicating whether the chart has plot area.
Declaration
bool HasPlotArea { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how to set the visibility of PlotArea.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set frame format
chart.ChartArea.IsBorderCornersRound = true;
//Set HasPlotArea
chart.HasPlotArea = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
HasTitle
Gets or sets whether the chart has title.
Declaration
bool HasTitle { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how to set HasTitle property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set hasTitle
chart.HasTitle = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Height
Gets or sets the height of the chart in points (1/72 inch).
Declaration
double Height { get; set; }
Property Value
Type |
---|
System.Double |
Remarks
To know more about resizing chart and chart elements refer Resizing Chart.
Examples
The following code illustrates how Width and Height for the chart can be set.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart height and width
chart.Height = 300;
chart.Width = 300;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
HeightPercent
Gets or sets the height of a 3D chart as a percentage of the chart width (5 - 500 percent).
Declaration
int HeightPercent { get; set; }
Property Value
Type |
---|
System.Int32 |
Examples
The following code illustrates how HeightPercent can be set for charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set Chart height percent
chart.HeightPercent = 200;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
IsSeriesInRows
True to swap the data in DataRange over the axis. Series data is charted on the Y axis by default.
Declaration
bool IsSeriesInRows { get; set; }
Property Value
Type |
---|
System.Boolean |
Remarks
Data being charted on the X axis will move to the Y axis and vice versa.
Examples
The following code illustrates how to set IsSeriesInRows property for charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set IsSeriesInRows
chart.IsSeriesInRows = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Legend
Gets legend in the chart. Read-only.
Declaration
IChartLegend Legend { get; }
Property Value
Type |
---|
IChartLegend |
Remarks
This is a key that identifies patterns, colors or symbols associated with the markers of a chart data series. It shows data series name corresponding to each data marker.
Examples
The following code illustrates how to access IChartLegend using Legend property and set Position to Left.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart legend
IChartLegend legend = chart.Legend;
//Set legend position
legend.Position = ExcelLegendPosition.Left;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
PageSetup
Gets the page setup for the chart. Read-only.
Declaration
IChartPageSetup PageSetup { get; }
Property Value
Type |
---|
IChartPageSetup |
Examples
The following code illustrates how to set paper size.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = workbook.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart page setup
IChartPageSetup pageSetup = chart.PageSetup;
//Set paper size
pageSetup.PaperSize = ExcelPaperSize.A3TransversePaper;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Perspective
Gets or sets the perspective for the 3D chart view (0 to 100).
Declaration
int Perspective { get; set; }
Property Value
Type |
---|
System.Int32 |
Remarks
This property is ignored if the RightAngleAxes property is True.
Examples
The following code illustrates how to set Perspective for the charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set Chart perspective
chart.Perspective = 70;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
PivotChartType
Gets or sets the type of the pivot chart.
Declaration
ExcelChartType PivotChartType { get; set; }
Property Value
Type | Description |
---|---|
ExcelChartType | The type of the pivot chart. |
Examples
The following code illustrates how to set pivot chart type.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.ImportDataTable(getData(), true, 1, 1);
//Create pivot table
IPivotCache cache = workbook.PivotCaches.Add(sheet["A1:D21"]);
IPivotTable pivotTable = sheet.PivotTables.Add("PivotTable", sheet["F1"], cache);
pivotTable.Fields[0].Axis = PivotAxisTypes.Row;
pivotTable.Fields[1].Axis = PivotAxisTypes.Column;
pivotTable.Fields[2].Axis = PivotAxisTypes.Row;
IPivotField field = pivotTable.Fields[3];
pivotTable.DataFields.Add(field, "Sum", PivotSubtotalTypes.Sum);
//Create chart
IChart chart = sheet.Charts.Add();
//Set pivot source
chart.PivotSource = pivotTable;
//Set pivot chart type
chart.PivotChartType = ExcelChartType.Pie;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
System.Data.DataTable getData()
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("Region");
dt.Columns.Add("Employee");
dt.Columns.Add("Item");
dt.Columns.Add("Units");
dt.Rows.Add("Central", "Jones", "Pen Set", 700);
dt.Rows.Add("West", "Kivell", "Binder", 85);
dt.Rows.Add("East", "Gill", "Pen", 58);
dt.Rows.Add("Central", "Jones", "Pen Set", 46);
dt.Rows.Add("West", "Kivell", "Binder", 61);
dt.Rows.Add("Central", "Jones", "Pen", 90);
dt.Rows.Add("West", "Kivell", "Pen Set", 32);
dt.Rows.Add("East", "Gill", "Binder", 79);
dt.Rows.Add("Central", "Jones", "Pen Set", 27);
dt.Rows.Add("Central", "Jones", "Binder", 5);
dt.Rows.Add("East", "Gill", "Pen Set", 41);
dt.Rows.Add("East", "Gill", "Pen Set", 61);
dt.Rows.Add("East", "Gill", "Binder", 9);
dt.Rows.Add("Central", "Jones", "Pen Set", 75);
dt.Rows.Add("West", "Kivell", "Pen Set", 97);
dt.Rows.Add("West", "Kivell", "Pen Set", 86);
dt.Rows.Add("East", "Gill", "Pen Set", 90);
dt.Rows.Add("East", "Gill", "Pen Set", 25);
dt.Rows.Add("East", "Gill", "Binder", 68);
dt.Rows.Add("East", "Gill", "Binder", 19);
return dt;
}
PivotSource
Gets or sets the pivot source.
Declaration
IPivotTable PivotSource { get; set; }
Property Value
Type | Description |
---|---|
IPivotTable | The pivot source |
Remarks
To know more about pivot tables refer Working with Pivot Tables.
Examples
The following code illustrates how to set data source for the PivotSource property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.ImportDataTable(getData(), true, 1, 1);
//Create pivot table
IPivotCache cache = workbook.PivotCaches.Add(sheet["A1:D21"]);
IPivotTable pivotTable = sheet.PivotTables.Add("PivotTable", sheet["F1"], cache);
pivotTable.Fields[0].Axis = PivotAxisTypes.Row;
pivotTable.Fields[1].Axis = PivotAxisTypes.Column;
pivotTable.Fields[2].Axis = PivotAxisTypes.Row;
IPivotField field = pivotTable.Fields[3];
pivotTable.DataFields.Add(field, "Sum", PivotSubtotalTypes.Sum);
//Create chart
IChart chart = sheet.Charts.Add();
//Set pivot source
chart.PivotSource = pivotTable;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
System.Data.DataTable getData()
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("Region");
dt.Columns.Add("Employee");
dt.Columns.Add("Item");
dt.Columns.Add("Units");
dt.Rows.Add("Central", "Jones", "Pen Set", 700);
dt.Rows.Add("West", "Kivell", "Binder", 85);
dt.Rows.Add("East", "Gill", "Pen", 58);
dt.Rows.Add("Central", "Jones", "Pen Set", 46);
dt.Rows.Add("West", "Kivell", "Binder", 61);
dt.Rows.Add("Central", "Jones", "Pen", 90);
dt.Rows.Add("West", "Kivell", "Pen Set", 32);
dt.Rows.Add("East", "Gill", "Binder", 79);
dt.Rows.Add("Central", "Jones", "Pen Set", 27);
dt.Rows.Add("Central", "Jones", "Binder", 5);
dt.Rows.Add("East", "Gill", "Pen Set", 41);
dt.Rows.Add("East", "Gill", "Pen Set", 61);
dt.Rows.Add("East", "Gill", "Binder", 9);
dt.Rows.Add("Central", "Jones", "Pen Set", 75);
dt.Rows.Add("West", "Kivell", "Pen Set", 97);
dt.Rows.Add("West", "Kivell", "Pen Set", 86);
dt.Rows.Add("East", "Gill", "Pen Set", 90);
dt.Rows.Add("East", "Gill", "Pen Set", 25);
dt.Rows.Add("East", "Gill", "Binder", 68);
dt.Rows.Add("East", "Gill", "Binder", 19);
return dt;
}
PlotArea
Gets the plot area where the chart data is plotted. Read-only.
Declaration
IChartFrameFormat PlotArea { get; }
Property Value
Type |
---|
IChartFrameFormat |
Remarks
The plot area on a 2-D chart contains the data markers, grid lines, data labels, trend lines, and optional chart items placed in the chart area. The plot area on a 3-D chart contains all the above items plus the walls and floor. The plot area is surrounded by the chart area.
Examples
The following code illustrates how to access IChartFrameFormat using PlotArea property and set foreground color for the chart's PlotArea.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart frame format
IChartFrameFormat frameFormat = chart.PlotArea;
//Set color
frameFormat.Fill.ForeColor = System.Drawing.Color.Red;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
PlotVisibleOnly
True if only visible cells are plotted. False if both visible and hidden cells are plotted.
Declaration
bool PlotVisibleOnly { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
By default PlotVisibleOnly property is set to "true" so only cells which are visible within the chart's DataRange will be plotted in chart. Here for example, we set PlotVisibleOnly to "false" so that chart plots all the cells within the chart's DataRange.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Hide column
sheet.Columns[2].ColumnWidth = 0;
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set Plot visible only
chart.PlotVisibleOnly = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
PrimaryCategoryAxis
Gets the primary category axis of the chart. Read-only.
Declaration
IChartCategoryAxis PrimaryCategoryAxis { get; }
Property Value
Type |
---|
IChartCategoryAxis |
Remarks
Charts are plotted using X and Y axes. The Y axes typically have numerical scales, whereas the X axes typically have categorical scales. Some charts, for example, have axes, and others, like PieChart don't. Most charts have horizontal axis of type PrimaryCategoryAxis and vertical axis of type PrimaryValueAxis but some, like BarChart, have the opposite. PrimaryCategoryAxis represents an axis used for categories. Categories can include string, numeric, and date values.
Examples
The following code illustrates how to set the visibility of PrimaryCategoryAxis.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set visibility
categoryAxis.Visible = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
PrimarySerieAxis
Gets the primary series axis. Read-only.
Declaration
IChartSeriesAxis PrimarySerieAxis { get; }
Property Value
Type |
---|
IChartSeriesAxis |
Remarks
This is the depth axis showing the depth of the third dimension in 3D charts.
Examples
The following code illustrates how to set visibility of PrimarySerieAxis.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart type
chart.ChartType = ExcelChartType.Surface_3D;
//Chart value axis
IChartSeriesAxis seriesAxis = chart.PrimarySerieAxis;
//Set visibility
seriesAxis.Visible = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
PrimaryValueAxis
Gets the primary value axis. Read-only.
Declaration
IChartValueAxis PrimaryValueAxis { get; }
Property Value
Type |
---|
IChartValueAxis |
Remarks
Charts are plotted using X and Y axes. The Y axes typically have numerical scales, whereas the X axes typically have categorical scales. Some charts, for example, have axes, and others, like PieChart don't. Most charts have horizontal axis of type PrimaryCategoryAxis and vertical axis of type PrimaryValueAxis but some, like BarChart, have the opposite. PrimaryValueAxis represents an axis used for series values.
Examples
The following code illustrates how to set visibility of PrimaryValueAxis.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Chart value axis
IChartValueAxis valueAxis = chart.PrimaryValueAxis;
//Set visibility
valueAxis.Visible = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
RightAngleAxes
True if the chart axes are at right angles, independent of chart rotation or elevation. otherwise False.
Declaration
bool RightAngleAxes { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how RightAngleAxes can be set for charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set perspective
chart.Perspective = 90;
//Set RightAngleAxes
chart.RightAngleAxes = true;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Rotation
Gets or sets the rotation of the 3D chart view (the rotation of the plot area around the z-axis, in degrees)-(0 to 360 degrees).
Declaration
int Rotation { get; set; }
Property Value
Type |
---|
System.Int32 |
Remarks
The value of this property must be from 0 to 360, except for 3-D bar charts, where the value must be from 0 to 44. The default value is 20. Applies only to 3-D charts.
Examples
The following code illustrates how to set Rotation for 3-D charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set Chart rotation
chart.Rotation = 10;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
SecondaryCategoryAxis
Gets the secondary category axis of the chart. Read-only.
Declaration
IChartCategoryAxis SecondaryCategoryAxis { get; }
Property Value
Type |
---|
IChartCategoryAxis |
Remarks
The most commonly used charts have a set of primary axes and may have a set of secondary axes. You can enable and disable this through Visible property.
Examples
The following code illustrates how to disable PrimaryCategoryAxis and set SecondaryCategoryAxis for charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
sheet.Range["A3"].Value = "100";
sheet.Range["B3"].Value = "200";
sheet.Range["C3"].Value = "300";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C3"];
//Set secondary axis
IChartSerie serie = chart.Series[1];
serie.UsePrimaryAxis = false;
chart.SecondaryCategoryAxis.Visible = true;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
SecondaryValueAxis
Gets the secondary value axis of the chart. Read-only.
Declaration
IChartValueAxis SecondaryValueAxis { get; }
Property Value
Type |
---|
IChartValueAxis |
Remarks
The most commonly used charts have a set of primary axes and may have a set of secondary axes. You can enable and disable this through UsePrimaryAxis property.
Examples
The following code illustrates how to disable PrimaryValueAxis and set SecondaryValueAxis for charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
sheet.Range["A3"].Value = "100";
sheet.Range["B3"].Value = "200";
sheet.Range["C3"].Value = "300";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C3"];
//Set secondary axis
IChartSerie serie = chart.Series[1];
serie.UsePrimaryAxis = false;
chart.SecondaryValueAxis.Visible = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Series
Gets the IChartSeries collection of the chart. Read-only.
Declaration
IChartSeries Series { get; }
Property Value
Type |
---|
IChartSeries |
Examples
The following code illustrates how to access the IChartSeries collection of a chart.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = workbook.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Chart series
IChartSeries series = chart.Series;
//Check count
Console.WriteLine(series.Count);
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//1
SeriesNameLevel
Gets or sets a value referring to the source level for series names.
Declaration
ExcelSeriesNameLevel SeriesNameLevel { get; set; }
Property Value
Type |
---|
ExcelSeriesNameLevel |
Examples
By default SeriesNameLevel is set to SeriesNameLevelAll. Here for example, we set SeriesNameLevelNone to SeriesNameLevel property to use autogenerated series labels.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Text = "Apr";
sheet.Range["B2"].Text = "May";
sheet.Range["C2"].Text = "Jun";
sheet.Range["A4"].Value = "10";
sheet.Range["B4"].Value = "20";
sheet.Range["C4"].Value = "30";
sheet.Range["A3"].Value = "15";
sheet.Range["B3"].Value = "10";
sheet.Range["C3"].Value = "35";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C4"];
//Set series in rows
chart.IsSeriesInRows = false;
//Set chart type
chart.ChartType = ExcelChartType.Line;
//Set Series name level
chart.SeriesNameLevel = ExcelSeriesNameLevel.SeriesNameLevelNone;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
ShowAllFieldButtons
Gets or sets a boolean value indicating whether to show all field buttons on a pivot chart.
Declaration
bool ShowAllFieldButtons { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Examples
The following code illustrates how to set the visibility of all the field buttons in the pivot chart.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.ImportDataTable(getData(), true, 1, 1);
//Create pivot table
IPivotCache cache = workbook.PivotCaches.Add(sheet["A1:D21"]);
IPivotTable pivotTable = sheet.PivotTables.Add("PivotTable", sheet["F1"], cache);
pivotTable.Fields[0].Axis = PivotAxisTypes.Row;
pivotTable.Fields[1].Axis = PivotAxisTypes.Column;
pivotTable.Fields[2].Axis = PivotAxisTypes.Row;
IPivotField field = pivotTable.Fields[3];
pivotTable.DataFields.Add(field, "Sum", PivotSubtotalTypes.Sum);
//Create chart
IChart chart = sheet.Charts.Add();
//Set pivot source
chart.PivotSource = pivotTable;
//Set button visibility
chart.ShowAllFieldButtons = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
System.Data.DataTable getData()
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("Region");
dt.Columns.Add("Employee");
dt.Columns.Add("Item");
dt.Columns.Add("Units");
dt.Rows.Add("Central", "Jones", "Pen Set", 700);
dt.Rows.Add("West", "Kivell", "Binder", 85);
dt.Rows.Add("East", "Gill", "Pen", 58);
dt.Rows.Add("Central", "Jones", "Pen Set", 46);
dt.Rows.Add("West", "Kivell", "Binder", 61);
dt.Rows.Add("Central", "Jones", "Pen", 90);
dt.Rows.Add("West", "Kivell", "Pen Set", 32);
dt.Rows.Add("East", "Gill", "Binder", 79);
dt.Rows.Add("Central", "Jones", "Pen Set", 27);
dt.Rows.Add("Central", "Jones", "Binder", 5);
dt.Rows.Add("East", "Gill", "Pen Set", 41);
dt.Rows.Add("East", "Gill", "Pen Set", 61);
dt.Rows.Add("East", "Gill", "Binder", 9);
dt.Rows.Add("Central", "Jones", "Pen Set", 75);
dt.Rows.Add("West", "Kivell", "Pen Set", 97);
dt.Rows.Add("West", "Kivell", "Pen Set", 86);
dt.Rows.Add("East", "Gill", "Pen Set", 90);
dt.Rows.Add("East", "Gill", "Pen Set", 25);
dt.Rows.Add("East", "Gill", "Binder", 68);
dt.Rows.Add("East", "Gill", "Binder", 19);
return dt;
}
ShowAxisFieldButtons
Gets or sets a boolean value indicating whether to show axis field buttons on a pivot chart.
Declaration
bool ShowAxisFieldButtons { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Examples
The following code illustrates how to set visibility of axis field buttons in pivot chart.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.ImportDataTable(getData(), true, 1, 1);
//Create pivot table
IPivotCache cache = workbook.PivotCaches.Add(sheet["A1:D21"]);
IPivotTable pivotTable = sheet.PivotTables.Add("PivotTable", sheet["F1"], cache);
pivotTable.Fields[0].Axis = PivotAxisTypes.Row;
pivotTable.Fields[1].Axis = PivotAxisTypes.Column;
pivotTable.Fields[2].Axis = PivotAxisTypes.Row;
IPivotField field = pivotTable.Fields[3];
pivotTable.DataFields.Add(field, "Sum", PivotSubtotalTypes.Sum);
//Create chart
IChart chart = sheet.Charts.Add();
//Set pivot source
chart.PivotSource = pivotTable;
//Set button visibility
chart.ShowAxisFieldButtons = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
System.Data.DataTable getData()
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("Region");
dt.Columns.Add("Employee");
dt.Columns.Add("Item");
dt.Columns.Add("Units");
dt.Rows.Add("Central", "Jones", "Pen Set", 700);
dt.Rows.Add("West", "Kivell", "Binder", 85);
dt.Rows.Add("East", "Gill", "Pen", 58);
dt.Rows.Add("Central", "Jones", "Pen Set", 46);
dt.Rows.Add("West", "Kivell", "Binder", 61);
dt.Rows.Add("Central", "Jones", "Pen", 90);
dt.Rows.Add("West", "Kivell", "Pen Set", 32);
dt.Rows.Add("East", "Gill", "Binder", 79);
dt.Rows.Add("Central", "Jones", "Pen Set", 27);
dt.Rows.Add("Central", "Jones", "Binder", 5);
dt.Rows.Add("East", "Gill", "Pen Set", 41);
dt.Rows.Add("East", "Gill", "Pen Set", 61);
dt.Rows.Add("East", "Gill", "Binder", 9);
dt.Rows.Add("Central", "Jones", "Pen Set", 75);
dt.Rows.Add("West", "Kivell", "Pen Set", 97);
dt.Rows.Add("West", "Kivell", "Pen Set", 86);
dt.Rows.Add("East", "Gill", "Pen Set", 90);
dt.Rows.Add("East", "Gill", "Pen Set", 25);
dt.Rows.Add("East", "Gill", "Binder", 68);
dt.Rows.Add("East", "Gill", "Binder", 19);
return dt;
}
ShowLegendFieldButtons
Gets or sets a boolean value indicating whether to show legend field buttons on a pivot chart.
Declaration
bool ShowLegendFieldButtons { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Examples
The following code illustrates how to set visibility of legend field buttons in pivot charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.ImportDataTable(getData(), true, 1, 1);
//Create pivot table
IPivotCache cache = workbook.PivotCaches.Add(sheet["A1:D21"]);
IPivotTable pivotTable = sheet.PivotTables.Add("PivotTable", sheet["F1"], cache);
pivotTable.Fields[0].Axis = PivotAxisTypes.Row;
pivotTable.Fields[1].Axis = PivotAxisTypes.Column;
pivotTable.Fields[2].Axis = PivotAxisTypes.Row;
IPivotField field = pivotTable.Fields[3];
pivotTable.DataFields.Add(field, "Sum", PivotSubtotalTypes.Sum);
//Create chart
IChart chart = sheet.Charts.Add();
//Set pivot source
chart.PivotSource = pivotTable;
//Set button visibility
chart.ShowLegendFieldButtons = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
System.Data.DataTable getData()
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("Region");
dt.Columns.Add("Employee");
dt.Columns.Add("Item");
dt.Columns.Add("Units");
dt.Rows.Add("Central", "Jones", "Pen Set", 700);
dt.Rows.Add("West", "Kivell", "Binder", 85);
dt.Rows.Add("East", "Gill", "Pen", 58);
dt.Rows.Add("Central", "Jones", "Pen Set", 46);
dt.Rows.Add("West", "Kivell", "Binder", 61);
dt.Rows.Add("Central", "Jones", "Pen", 90);
dt.Rows.Add("West", "Kivell", "Pen Set", 32);
dt.Rows.Add("East", "Gill", "Binder", 79);
dt.Rows.Add("Central", "Jones", "Pen Set", 27);
dt.Rows.Add("Central", "Jones", "Binder", 5);
dt.Rows.Add("East", "Gill", "Pen Set", 41);
dt.Rows.Add("East", "Gill", "Pen Set", 61);
dt.Rows.Add("East", "Gill", "Binder", 9);
dt.Rows.Add("Central", "Jones", "Pen Set", 75);
dt.Rows.Add("West", "Kivell", "Pen Set", 97);
dt.Rows.Add("West", "Kivell", "Pen Set", 86);
dt.Rows.Add("East", "Gill", "Pen Set", 90);
dt.Rows.Add("East", "Gill", "Pen Set", 25);
dt.Rows.Add("East", "Gill", "Binder", 68);
dt.Rows.Add("East", "Gill", "Binder", 19);
return dt;
}
ShowReportFilterFieldButtons
Gets or sets a boolean value indicating whether to show report filter field buttons on a pivot chart.
Declaration
bool ShowReportFilterFieldButtons { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Examples
The following code illustrates how to set visibility of report filter field buttons in pivot charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.ImportDataTable(getData(), true, 1, 1);
//Create pivot table
IPivotCache cache = workbook.PivotCaches.Add(sheet["A1:D21"]);
IPivotTable pivotTable = sheet.PivotTables.Add("PivotTable", sheet["F1"], cache);
pivotTable.Fields[0].Axis = PivotAxisTypes.Row;
pivotTable.Fields[1].Axis = PivotAxisTypes.Column;
pivotTable.Fields[2].Axis = PivotAxisTypes.Row;
IPivotField field = pivotTable.Fields[3];
pivotTable.DataFields.Add(field, "Sum", PivotSubtotalTypes.Sum);
//Create chart
IChart chart = sheet.Charts.Add();
//Set pivot source
chart.PivotSource = pivotTable;
//Set button visibility
chart.ShowReportFilterFieldButtons = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
System.Data.DataTable getData()
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("Region");
dt.Columns.Add("Employee");
dt.Columns.Add("Item");
dt.Columns.Add("Units");
dt.Rows.Add("Central", "Jones", "Pen Set", 700);
dt.Rows.Add("West", "Kivell", "Binder", 85);
dt.Rows.Add("East", "Gill", "Pen", 58);
dt.Rows.Add("Central", "Jones", "Pen Set", 46);
dt.Rows.Add("West", "Kivell", "Binder", 61);
dt.Rows.Add("Central", "Jones", "Pen", 90);
dt.Rows.Add("West", "Kivell", "Pen Set", 32);
dt.Rows.Add("East", "Gill", "Binder", 79);
dt.Rows.Add("Central", "Jones", "Pen Set", 27);
dt.Rows.Add("Central", "Jones", "Binder", 5);
dt.Rows.Add("East", "Gill", "Pen Set", 41);
dt.Rows.Add("East", "Gill", "Pen Set", 61);
dt.Rows.Add("East", "Gill", "Binder", 9);
dt.Rows.Add("Central", "Jones", "Pen Set", 75);
dt.Rows.Add("West", "Kivell", "Pen Set", 97);
dt.Rows.Add("West", "Kivell", "Pen Set", 86);
dt.Rows.Add("East", "Gill", "Pen Set", 90);
dt.Rows.Add("East", "Gill", "Pen Set", 25);
dt.Rows.Add("East", "Gill", "Binder", 68);
dt.Rows.Add("East", "Gill", "Binder", 19);
return dt;
}
ShowValueFieldButtons
Gets or sets a boolean value indicating whether to show value field buttons on a pivot chart.
Declaration
bool ShowValueFieldButtons { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Examples
The following code illustrates how to set the visibility of value field buttons in pivot chart.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.ImportDataTable(getData(), true, 1, 1);
//Create pivot table
IPivotCache cache = workbook.PivotCaches.Add(sheet["A1:D21"]);
IPivotTable pivotTable = sheet.PivotTables.Add("PivotTable", sheet["F1"], cache);
pivotTable.Fields[0].Axis = PivotAxisTypes.Row;
pivotTable.Fields[1].Axis = PivotAxisTypes.Column;
pivotTable.Fields[2].Axis = PivotAxisTypes.Row;
IPivotField field = pivotTable.Fields[3];
pivotTable.DataFields.Add(field, "Sum", PivotSubtotalTypes.Sum);
//Create chart
IChart chart = sheet.Charts.Add();
//Set pivot source
chart.PivotSource = pivotTable;
//Set button visibility
chart.ShowValueFieldButtons = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
System.Data.DataTable getData()
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("Region");
dt.Columns.Add("Employee");
dt.Columns.Add("Item");
dt.Columns.Add("Units");
dt.Rows.Add("Central", "Jones", "Pen Set", 700);
dt.Rows.Add("West", "Kivell", "Binder", 85);
dt.Rows.Add("East", "Gill", "Pen", 58);
dt.Rows.Add("Central", "Jones", "Pen Set", 46);
dt.Rows.Add("West", "Kivell", "Binder", 61);
dt.Rows.Add("Central", "Jones", "Pen", 90);
dt.Rows.Add("West", "Kivell", "Pen Set", 32);
dt.Rows.Add("East", "Gill", "Binder", 79);
dt.Rows.Add("Central", "Jones", "Pen Set", 27);
dt.Rows.Add("Central", "Jones", "Binder", 5);
dt.Rows.Add("East", "Gill", "Pen Set", 41);
dt.Rows.Add("East", "Gill", "Pen Set", 61);
dt.Rows.Add("East", "Gill", "Binder", 9);
dt.Rows.Add("Central", "Jones", "Pen Set", 75);
dt.Rows.Add("West", "Kivell", "Pen Set", 97);
dt.Rows.Add("West", "Kivell", "Pen Set", 86);
dt.Rows.Add("East", "Gill", "Pen Set", 90);
dt.Rows.Add("East", "Gill", "Pen Set", 25);
dt.Rows.Add("East", "Gill", "Binder", 68);
dt.Rows.Add("East", "Gill", "Binder", 19);
return dt;
}
SideWall
Gets the side wall of the 3D chart. Read-only.
Declaration
IChartWallOrFloor SideWall { get; }
Property Value
Type |
---|
IChartWallOrFloor |
Examples
The following code illustrates how to access IChartWallOrFloor using SideWall property and set foreground color for the chart's SideWall.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered_3D;
//Set chart wall or floor
IChartWallOrFloor wall = chart.SideWall;
//Set color
wall.Fill.FillType = ExcelFillType.SolidColor;
wall.Fill.ForeColor = System.Drawing.Color.Red;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
SizeWithWindow
True if the chart is resized to match the size of the chart sheet window. False if the chart size is not attached to the window size. Applies only to chart sheets.
Declaration
bool SizeWithWindow { get; set; }
Property Value
Type |
---|
System.Boolean |
Remarks
Used in older versions of Microsoft office.
Style
Gets or sets a style value for the chart.
Declaration
int Style { get; set; }
Property Value
Type |
---|
System.Int32 |
Examples
By default Style is set to 0. Here for example, we set Style property for style change.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set Chart Style
chart.Style = 14;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Walls
Gets the walls of the 3D chart. Read-only.
Declaration
IChartWallOrFloor Walls { get; }
Property Value
Type |
---|
IChartWallOrFloor |
Examples
The following code illustrates how to access IChartWallOrFloor using Walls property and set foreground color for the chart's Walls.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered_3D;
//Set chart wall or floor
IChartWallOrFloor wall = chart.Walls;
//Set color
wall.Fill.FillType = ExcelFillType.SolidColor;
wall.Fill.ForeColor = System.Drawing.Color.Red;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
WallsAndGridlines2D
True if grid lines are drawn two-dimensionally on a 3-D chart. otherwise False.
Declaration
bool WallsAndGridlines2D { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how to set WallsAndGridlines2D for charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set wall lines
chart.WallsAndGridlines2D = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Width
Gets or sets the width of the chart in points (1/72 inch).
Declaration
double Width { get; set; }
Property Value
Type |
---|
System.Double |
Remarks
To know more about resizing chart and chart elements refer Resizing Chart.
Examples
The following code illustrates how Width and Height for the chart can be set.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart height and width
chart.Height = 300;
chart.Width = 300;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
XPos
Gets or sets the X coordinate of upper-left corner of the chart in points (1/72 inch).
Declaration
double XPos { get; set; }
Property Value
Type |
---|
System.Double |
Examples
The following code illustrates how to set X coordinate of upper-left corner of the charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart type
chart.Height = 300;
chart.Width = 300;
//Set position
chart.XPos = 250;
chart.YPos = 30;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
YPos
Gets or sets the Y coordinate of upper-left corner of the chart in points (1/72 inch).
Declaration
double YPos { get; set; }
Property Value
Type |
---|
System.Double |
Examples
The following code illustrates how to set Y coordinate of upper-left corner of the charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart type
chart.Height = 300;
chart.Width = 300;
//Set position
chart.XPos = 250;
chart.YPos = 30;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}