Chart

Chart class

Encapsulates the object that represents a single Excel chart.

public class Chart

Properties

Name Description
ActualChartSize { get; } Gets actual size of chart
AutoScaling { get; set; } True if Microsoft Excel scales a 3-D chart so that it’s closer in size to the equivalent 2-D chart. The RightAngleAxes property must be True.
BackWall { get; } Returns a Walls object that represents the back wall of a 3-D chart.
CategoryAxis { get; } Gets the chart’s X axis.
ChartArea { get; } Gets the chart area in the worksheet
ChartDataTable { get; } Represents the chart data table.
ChartObject { get; } Represents the chartShape;
DepthPercent { get; set; } Represents the depth of a 3-D chart as a percentage of the chart width (between 20 and 2000 percent).
DisplayNaAsBlank { get; set; } Indicates whether displaying #N/A as blank value.
Elevation { get; set; } Represents the elevation of the 3-D chart view, in degrees.
FirstSliceAngle { get; set; } Gets or sets the angle of the first pie-chart or doughnut-chart slice, in degrees (clockwise from vertical). Applies only to pie, 3-D pie, and doughnut charts, 0 to 360.
Floor { get; } Returns a Floor object that represents the walls of a 3-D chart.
GapDepth { get; set; } Gets or sets the distance between the data series in a 3-D chart, as a percentage of the marker width. The value of this property must be between 0 and 500.
GapWidth { get; set; } Returns or sets the space between bar or column clusters, as a percentage of the bar or column width. The value of this property must be between 0 and 500.
HeightPercent { get; set; } Returns or sets the height of a 3-D chart as a percentage of the chart width (between 5 and 500 percent).
HidePivotFieldButtons { get; set; } Indicates whether hide the pivot chart field buttons only when the chart is PivotChart
Is3D { get; } Indicates whether the chart is a 3d chart.
IsRectangularCornered { get; set; } Gets or sets a value indicating whether the chart area is rectangular cornered. Default is true.
Legend { get; } Gets the chart legend.
Line { get; } Gets the line.
Name { get; set; } Gets and sets the name of the chart.
NSeries { get; } Gets a SeriesCollection collection representing the data series in the chart.
PageSetup { get; } Represents the page setup description in this chart.
Perspective { get; set; } Returns or sets the perspective for the 3-D chart view. Must be between 0 and 100. This property is ignored if the RightAngleAxes property is True.
PivotOptions { get; } Specifies the pivot controls that appear on the chart
PivotSource { get; set; } The source is the data of the pivotTable. If PivotSource is not empty ,the chart is PivotChart.
Placement { get; set; } Represents the way the chart is attached to the cells below it.
PlotArea { get; } Gets the chart’s plot area which includes axis tick labels.
PlotBy { get; } Gets and sets whether plot by row or column.
PlotEmptyCellsType { get; set; } Gets and sets how to plot the empty cells.
PlotVisibleCells { get; set; } Indicates whether only plot visible cells.
PrintSize { get; set; } Gets and sets the printed chart size.
RightAngleAxes { get; set; } True if the chart axes are at right angles. Applies only for 3-D charts(except Column3D and 3-D Pie Charts).
RotationAngle { get; set; } Represents the rotation of the 3-D chart view (the rotation of the plot area around the z-axis, in degrees).
SecondCategoryAxis { get; } Gets the chart’s second X axis.
SecondValueAxis { get; } Gets the chart’s second Y axis.
SeriesAxis { get; } Gets the chart’s series axis.
Shapes { get; } Returns all drawing shapes in this chart.
ShowDataTable { get; set; } Gets or sets a value indicating whether the chart displays a data table.
ShowLegend { get; set; } Gets or sets a value indicating whether the chart legend will be displayed. Default is true.
SideWall { get; } Returns a Walls object that represents the side wall of a 3-D chart.
SizeWithWindow { get; set; } True if Microsoft Excel resizes the chart to match the size of the chart sheet window.
Style { get; set; } Gets and sets the builtin style.
SubTitle { get; } Gets the chart’s sub-title. Only for ODS format file.
Title { get; } Gets the chart’s title.
Type { get; set; } Gets or sets a chart’s type.
ValueAxis { get; } Gets the chart’s Y axis.
Walls { get; } Returns a Walls object that represents the walls of a 3-D chart.
WallsAndGridlines2D { get; set; } True if gridlines are drawn two-dimensionally on a 3-D chart.
Worksheet { get; } Gets the worksheet which contains this chart.

Methods

Name Description
Calculate() Calculates the custom position of plot area, axes if the position of them are auto assigned.
GetChartDataRange() Gets the data source range of the chart .
HasAxis(AxisType, bool) Returns which axes exist on the chart.
IsChartDataChanged() Detects if a chart’s data source has changed.
Move(int, int, int, int) Moves the chart to a specified location.
RefreshPivotData() Refreshes pivot chart’s data from it’s pivot data source.
SetChartDataRange(string, bool) Specifies data range for a chart.
SwitchRowColumn() Switches row/column.
ToImage() Gets a 32-bit Bitmap object of the chart.
ToImage(ImageOrPrintOptions) Gets a 32-bit Bitmap object of the chart. ImageOrPrintOptions.ImageFormat, ImageOrPrintOptions.TiffCompression and ImageOrPrintOptions.Quality attributes are ignored.
ToImage(string) Creates the chart image and saves it to a file. The extension of the file name determines the format of the image.
ToImage(Stream, ImageFormat) Creates the chart image and saves it to a stream in the specified format.
ToImage(Stream, ImageOrPrintOptions) Creates the chart image and saves it to a stream in the specified format.
ToImage(Stream, long) Creates the chart image and saves it to a stream in the Jpeg format.
ToImage(string, ImageFormat) Creates the chart image and saves it to a file in the specified format.
ToImage(string, ImageOrPrintOptions) Creates the chart image and saves it to a file. The extension of the file name determines the format of the image.
ToImage(string, long) Creates the chart image and saves it to a file in the Jpeg format.
ToPdf(Stream) Creates the chart pdf and saves it to a stream.
ToPdf(string) Saves the chart to a pdf file.
ToPdf(Stream, float, float, PageLayoutAlignmentType, PageLayoutAlignmentType) Creates the chart pdf and saves it to a stream.
ToPdf(string, float, float, PageLayoutAlignmentType, PageLayoutAlignmentType) Saves the chart to a pdf file.

Examples

[C#]

Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];

Cells cells = sheet.Cells;
cells[0,1].PutValue("Income");
cells[1,0].PutValue("Company A");
cells[2,0].PutValue("Company B");
cells[3,0].PutValue("Company C");
cells[1,1].PutValue(10000);
cells[2,1].PutValue(20000);
cells[3,1].PutValue(30000);
		
int chartIndex = sheet.Charts.Add(ChartType.Column, 9, 9, 21, 15);

Chart chart = sheet.Charts[chartIndex];
chart.SetChartDataRange("A1:B4", true);
chart.ShowLegend = true;
chart.Title.Text = "Income Analysis";

[Visual Basic]

Dim workbook as Workbook = new Workbook()
Dim sheet as Worksheet = workbook.Worksheets(0)

Dim cells as Cells = sheet.Cells
cells(0,1).PutValue("Income")
cells(1,0).PutValue("Company A")
cells(2,0).PutValue("Company B")
cells(3,0).PutValue("Company C")
cells(1,1).PutValue(10000)
cells(2,1).PutValue(20000)
cells(3,1).PutValue(30000)
		
Dim chartIndex as Integer = sheet.Charts.Add(ChartType.Column, 9, 9, 21, 15)

Dim chart as Chart = sheet.Charts(chartIndex) 
chart.SetChartDataRange("A1:B4", True);
chart.ShowLegend = True
chart.Title.Text = "Income Analysis"

See Also