public class Chart
extends java.lang.Object
Example
The following codes show how to create a chart with .Net codes.
Workbook workbook = new Workbook();
Worksheet sheet = workbook.getWorksheets().get(0);
Cells cells = sheet.getCells();
cells.get(0,1).putValue("Income");
cells.get(1,0).putValue("Company A");
cells.get(2,0).putValue("Company B");
cells.get(3,0).putValue("Company C");
cells.get(1,1).putValue(10000);
cells.get(2,1).putValue(20000);
cells.get(3,1).putValue(30000);
int chartIndex = sheet.getCharts().add(ChartType.COLUMN, 9, 9, 21, 15);
Chart chart = sheet.getCharts().get(chartIndex);
chart.setChartDataRange("A1:B4", true);
chart.setShowLegend(true);
chart.getTitle().setText("Income Analysis");
| Modifier and Type | Method and Description |
|---|---|
void |
calculate()
Calculates the custom position of plot area, axes if the position of them are auto assigned.
|
void |
calculate(ChartCalculateOptions calculateOptions)
Calculates the custom position of plot area, axes if the position of them are auto assigned, with Chart Calculate Options.
|
void |
changeTemplate(byte[] data)
Change chart type with preset template.
|
int[] |
getActualChartSize()
Deprecated.
Use Chart.getActualSize() method instead.
|
int[] |
getActualSize()
Gets actual size of chart in unit of pixels.
|
boolean |
getAutoScaling()
True if Microsoft Excel scales a 3-D chart so that it's closer in size to the equivalent 2-D chart.
|
Walls |
getBackWall()
Returns a
getWalls() object that represents the back wall of a 3-D chart. |
Axis |
getCategoryAxis()
Gets the chart's X axis.
|
ChartArea |
getChartArea()
Gets the chart area in the worksheet.
|
java.lang.String |
getChartDataRange()
Gets the data source range of the chart.
|
ChartDataTable |
getChartDataTable()
Represents the chart data table.
|
ChartShape |
getChartObject()
Represents the chartShape;
|
ChartShape |
getChartShape()
Deprecated.
Use Aspose.Cells.Charts.Chart.ChartObject property instead.
|
int |
getDepthPercent()
Represents the depth of a 3-D chart as a percentage of the chart width (between 20 and 2000 percent).
|
boolean |
getDisplayNaAsBlank()
Indicates whether displaying #N/A as blank value.
|
int |
getElevation()
Represents the elevation of the 3-D chart view, in degrees.
|
SeriesCollection |
getFilteredNSeries()
Gets a
SeriesCollection collection representing the data series that are filtered in the chart. |
int |
getFirstSliceAngle()
Gets the angle of the first pie-chart or doughnut-chart slice, in degrees (clockwise from vertical).
|
Floor |
getFloor()
Returns a
getFloor() object that represents the walls of a 3-D chart. |
int |
getGapDepth()
Gets the distance between the data series in a 3-D chart, as a percentage of the marker width.
|
int |
getGapWidth()
Returns or sets the space between bar or column clusters, as a percentage of the bar or column width.
|
int |
getHeightPercent()
Returns or sets the height of a 3-D chart as a percentage of the chart width (between 5 and 500 percent).
|
boolean |
getHidePivotFieldButtons()
Indicates whether hide the pivot chart field buttons only when the chart is PivotChart.
|
boolean |
getIs3D()
Indicates whether the chart is a 3d chart.
|
Legend |
getLegend()
Gets the chart legend.
|
Line |
getLine()
Gets the line.
|
java.lang.String |
getName()
Gets the name of the chart.
|
SeriesCollection |
getNSeries()
Gets a
SeriesCollection collection representing the data series in the chart. |
PageSetup |
getPageSetup()
Represents the page setup description in this chart.
|
short |
getPerspective()
Returns or sets the perspective for the 3-D chart view.
|
PivotOptions |
getPivotOptions()
Specifies the pivot controls that appear on the chart
|
java.lang.String |
getPivotSource()
The source is the data of the pivotTable.
|
int |
getPlacement()
Represents the way the chart is attached to the cells below it.
|
PlotArea |
getPlotArea()
Gets the chart's plot area which includes axis tick labels.
|
int |
getPlotBy()
Gets whether plot by row or column.
|
int |
getPlotEmptyCellsType()
Gets how to plot the empty cells.
|
boolean |
getPlotVisibleCells()
Deprecated.
Use PlotVisibleCellsOnly property instead.
|
boolean |
getPlotVisibleCellsOnly()
Indicates whether plot visible cells only.
|
int |
getPrintSize()
Gets the printed chart size.
|
boolean |
getRightAngleAxes()
True if the chart axes are at right angles.
|
int |
getRotationAngle()
Represents the rotation of the 3-D chart view (the rotation of the plot area around the z-axis, in degrees).
|
Axis |
getSecondCategoryAxis()
Gets the chart's second X axis.
|
Axis |
getSecondValueAxis()
Gets the chart's second Y axis.
|
Axis |
getSeriesAxis()
Gets the chart's series axis.
|
ShapeCollection |
getShapes()
Returns all drawing shapes in this chart.
|
boolean |
getShowDataTable()
Gets a value indicating whether the chart displays a data table.
|
boolean |
getShowLegend()
Gets a value indicating whether the chart legend will be displayed.
|
Walls |
getSideWall()
Returns a
getWalls() object that represents the side wall of a 3-D chart. |
boolean |
getSizeWithWindow()
True if Microsoft Excel resizes the chart to match the size of the chart sheet window.
|
int |
getStyle()
Gets the builtin style.
|
Title |
getSubTitle()
Gets the chart's sub-title.
|
Title |
getTitle()
Gets the chart's title.
|
int |
getType()
Gets a chart's type.
|
Axis |
getValueAxis()
Gets the chart's Y axis.
|
Walls |
getWalls()
Returns a
getWalls() object that represents the walls of a 3-D chart. |
boolean |
getWallsAndGridlines2D()
True if gridlines are drawn two-dimensionally on a 3-D chart.
|
Worksheet |
getWorksheet()
Gets the worksheet which contains this chart.
|
boolean |
hasAxis(int aixsType,
boolean isPrimary)
Returns which axes exist on the chart.
|
boolean |
isCellReferedByChart(int sheetIndex,
int rowIndex,
int columnIndex)
Returns whether the cell refered by the chart.
|
boolean |
isChartDataChanged()
Detects if a chart's data source has changed.
|
boolean |
isRectangularCornered()
Gets a value indicating whether the chart area is rectangular cornered.
|
boolean |
isReferedByChart(int rowIndex,
int columnIndex)
Deprecated.
Use Chart.IsCellReferedByChart(int,int,int) method instead.
|
void |
move(int upperLeftRow,
int upperLeftColumn,
int lowerRightRow,
int lowerRightColumn)
Moves the chart to a specified location.
|
void |
refreshPivotData()
Refreshes chart's data from pivot table.
|
void |
setAutoScaling(boolean value)
True if Microsoft Excel scales a 3-D chart so that it's closer in size to the equivalent 2-D chart.
|
void |
setChartDataRange(java.lang.String area,
boolean isVertical)
Specifies data range for a chart.
|
void |
setDepthPercent(int value)
Represents the depth of a 3-D chart as a percentage of the chart width (between 20 and 2000 percent).
|
void |
setDisplayNaAsBlank(boolean value)
Indicates whether displaying #N/A as blank value.
|
void |
setElevation(int value)
Represents the elevation of the 3-D chart view, in degrees.
|
void |
setFirstSliceAngle(int value)
Sets the angle of the first pie-chart or doughnut-chart slice, in degrees (clockwise from vertical).
|
void |
setGapDepth(int value)
Sets the distance between the data series in a 3-D chart, as a percentage of the marker width.
|
void |
setGapWidth(int value)
Returns or sets the space between bar or column clusters, as a percentage of the bar or column width.
|
void |
setHeightPercent(int value)
Returns or sets the height of a 3-D chart as a percentage of the chart width (between 5 and 500 percent).
|
void |
setHidePivotFieldButtons(boolean value)
Indicates whether hide the pivot chart field buttons only when the chart is PivotChart.
|
void |
setName(java.lang.String value)
Sets the name of the chart.
|
void |
setPerspective(short value)
Returns or sets the perspective for the 3-D chart view.
|
void |
setPivotSource(java.lang.String value)
The source is the data of the pivotTable.
|
void |
setPlacement(int value)
Represents the way the chart is attached to the cells below it.
|
void |
setPlotEmptyCellsType(int value)
Sets how to plot the empty cells.
|
void |
setPlotVisibleCells(boolean value)
Deprecated.
Use PlotVisibleCellsOnly property instead.
|
void |
setPlotVisibleCellsOnly(boolean value)
Indicates whether plot visible cells only.
|
void |
setPrintSize(int value)
Sets the printed chart size.
|
void |
setRectangularCornered(boolean value)
Sets a value indicating whether the chart area is rectangular cornered.
|
void |
setRightAngleAxes(boolean value)
True if the chart axes are at right angles.
|
void |
setRotationAngle(int value)
Represents the rotation of the 3-D chart view (the rotation of the plot area around the z-axis, in degrees).
|
void |
setShowDataTable(boolean value)
Sets a value indicating whether the chart displays a data table.
|
void |
setShowLegend(boolean value)
Sets a value indicating whether the chart legend will be displayed.
|
void |
setSizeWithWindow(boolean value)
True if Microsoft Excel resizes the chart to match the size of the chart sheet window.
|
void |
setStyle(int value)
Sets the builtin style.
|
void |
setType(int value)
Sets a chart's type.
|
void |
setWallsAndGridlines2D(boolean value)
True if gridlines are drawn two-dimensionally on a 3-D chart.
|
boolean |
switchRowColumn()
Switches row/column.
|
void |
toImage(java.io.OutputStream stream,
ImageOrPrintOptions options)
Creates the chart image and saves it to a stream in the specified format.
|
void |
toImage(java.lang.String imageFile)
Creates the chart image and saves it to a file.
|
void |
toImage(java.lang.String imageFile,
ImageFormat imageFormat)
Deprecated.
Use Chart.ToImage(string, ImageType) method instead.
|
void |
toImage(java.lang.String imageFile,
ImageOrPrintOptions options)
Creates the chart image and saves it to a file.
|
void |
toImage(java.lang.String imageFile,
int imageType)
Creates the chart image and saves it to a file in the specified image type.
|
void |
toImage(java.lang.String imageFile,
long jpegQuality)
Deprecated.
Use Chart.ToImage(string,ImageOrPrintOptions) method instead.
|
void |
toPdf(java.io.OutputStream stream)
Creates the chart pdf and saves it to a stream.
|
void |
toPdf(java.io.OutputStream stream,
float desiredPageWidth,
float desiredPageHeight,
int hAlignmentType,
int vAlignmentType)
Creates the chart pdf and saves it to a stream.
|
void |
toPdf(java.lang.String fileName)
Saves the chart to a pdf file.
|
void |
toPdf(java.lang.String fileName,
float desiredPageWidth,
float desiredPageHeight,
int hAlignmentType,
int vAlignmentType)
Saves the chart to a pdf file.
|
public int getStyle()
Remarks
It should be between 1 and 48. Return -1 if it's not be set.public void setStyle(int value)
Remarks
It should be between 1 and 48. Return -1 if it's not be set.public ChartShape getChartObject()
public boolean getHidePivotFieldButtons()
public void setHidePivotFieldButtons(boolean value)
public PivotOptions getPivotOptions()
public java.lang.String getPivotSource()
Remarks
If the pivot table "PivotTable1" in the Worksheet "Sheet1" in the file "Book1.xls". The pivotSource could be "[Book1.xls]Sheet1!PivotTable1" if the chart and the PivotTable is not in the same workbook. If you set this property ,the previous data source setting will be lost.public void setPivotSource(java.lang.String value)
Remarks
If the pivot table "PivotTable1" in the Worksheet "Sheet1" in the file "Book1.xls". The pivotSource could be "[Book1.xls]Sheet1!PivotTable1" if the chart and the PivotTable is not in the same workbook. If you set this property ,the previous data source setting will be lost.public boolean isReferedByChart(int rowIndex,
int columnIndex)
Remarks
NOTE: This method is now obsolete. Instead, please use IsCellReferedByChart(int,int,int) method. This method will be removed 12 months later since April 2023. Aspose apologizes for any inconvenience you may have experienced.rowIndex - The row indexcolumnIndex - The column indexpublic boolean isCellReferedByChart(int sheetIndex,
int rowIndex,
int columnIndex)
sheetIndex - The sheet Index.-1 means the worksheet which contains current chart.rowIndex - The row indexcolumnIndex - The column indexpublic boolean isChartDataChanged()
Remarks
The method detects the changes in the chart's data source before rendering the chart to image format. At first Chart.toImage call, the chart source data (e.g. XValuesParseData, ValuesParseData) will be recorded. Before calling the Chart.toImage method again, call IsChartDataChanged method to check if Chart needs re-rendering.public int getPlotBy()
See PlotDataByType.
public void refreshPivotData()
Remarks
We will gather data from pivot data source to the pivot table report. This method is only used to gather all data to a pivot chart.public int getPlotEmptyCellsType()
See PlotEmptyCellsType.
public void setPlotEmptyCellsType(int value)
See PlotEmptyCellsType.
public boolean getPlotVisibleCells()
Remarks
NOTE: This member is now obsolete. Instead, please use PlotVisibleCellsOnly property. This method will be removed 12 months later since December 2022. Aspose apologizes for any inconvenience you may have experienced.public void setPlotVisibleCells(boolean value)
Remarks
NOTE: This member is now obsolete. Instead, please use PlotVisibleCellsOnly property. This method will be removed 12 months later since December 2022. Aspose apologizes for any inconvenience you may have experienced.public boolean getPlotVisibleCellsOnly()
public void setPlotVisibleCellsOnly(boolean value)
public boolean getDisplayNaAsBlank()
public void setDisplayNaAsBlank(boolean value)
public java.lang.String getName()
public void setName(java.lang.String value)
public boolean getSizeWithWindow()
public void setSizeWithWindow(boolean value)
public Worksheet getWorksheet()
public ShapeCollection getShapes()
public int getPrintSize()
See PrintSizeType.
public void setPrintSize(int value)
See PrintSizeType.
public void changeTemplate(byte[] data)
data - The data of chart template file(.crtx).public int getType()
See ChartType.
public void setType(int value)
See ChartType.
public void move(int upperLeftRow,
int upperLeftColumn,
int lowerRightRow,
int lowerRightColumn)
upperLeftColumn - Upper left column index.upperLeftRow - Upper left row index.lowerRightColumn - Lower right column indexlowerRightRow - Lower right row indexpublic SeriesCollection getNSeries()
SeriesCollection collection representing the data series in the chart.public SeriesCollection getFilteredNSeries()
SeriesCollection collection representing the data series that are filtered in the chart.public Title getTitle()
public Title getSubTitle()
public PlotArea getPlotArea()
Remarks
public ChartArea getChartArea()
public Axis getCategoryAxis()
public Axis getValueAxis()
public Axis getSecondValueAxis()
public Axis getSecondCategoryAxis()
public Axis getSeriesAxis()
public Legend getLegend()
public ChartDataTable getChartDataTable()
public boolean getShowLegend()
public void setShowLegend(boolean value)
public boolean isRectangularCornered()
public void setRectangularCornered(boolean value)
public boolean getShowDataTable()
public void setShowDataTable(boolean value)
public int getFirstSliceAngle()
public void setFirstSliceAngle(int value)
public int getGapWidth()
public void setGapWidth(int value)
public int getGapDepth()
public void setGapDepth(int value)
public void calculate()
public void calculate(ChartCalculateOptions calculateOptions)
public Floor getFloor()
getFloor() object that represents the walls of a 3-D chart.
Remarks
This property doesn't apply to 3-D pie charts.public Walls getWalls()
getWalls() object that represents the walls of a 3-D chart.
Remarks
This property doesn't apply to 3-D pie charts.public Walls getBackWall()
getWalls() object that represents the back wall of a 3-D chart.public Walls getSideWall()
getWalls() object that represents the side wall of a 3-D chart.public boolean getWallsAndGridlines2D()
public void setWallsAndGridlines2D(boolean value)
public int getRotationAngle()
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.public void setRotationAngle(int value)
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.public int getElevation()
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.public void setElevation(int value)
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.public boolean getRightAngleAxes()
Remarks
If this property is True, the Perspective property is ignored.public void setRightAngleAxes(boolean value)
Remarks
If this property is True, the Perspective property is ignored.public boolean getAutoScaling()
public void setAutoScaling(boolean value)
public int getHeightPercent()
public void setHeightPercent(int value)
public short getPerspective()
public void setPerspective(short value)
public boolean getIs3D()
public int getDepthPercent()
public void setDepthPercent(int value)
public void toImage(java.lang.String imageFile)
Remarks
The format of the image is specified by using the extension of the file name. For example, if you specify "myfile.png", then the image will be saved in the PNG format. The following file extensions are recognized: .bmp, .gif, .png, .jpg, .jpeg, .tiff, .tif, .emf.
If the width or height is zero or the chart is not supported according to Supported Charts List, this method will do nothing.imageFile - The image file name with full path.public void toImage(java.lang.String imageFile,
ImageFormat imageFormat)
Remarks
NOTE: This member is now obsolete. Instead, please use Chart.ToImage(string, ImageType) method. This property will be removed 12 months later since July 2022. Aspose apologizes for any inconvenience you may have experienced.imageFile - The image file name with full path.imageFormat - The format in which to save the image.public void toImage(java.lang.String imageFile,
int imageType)
Remarks
The type of the image is specified by using imageType.
The following types are supported:
ImageType.Bmp, ImageType.Gif, ImageType.Png, ImageType.Jpeg, ImageType.Tiff, ImageType.Emf.
imageFile - The image file name with full path.imageType - ImageType. The image type in which to save the image.public void toImage(java.lang.String imageFile,
long jpegQuality)
Remarks
If the width or height is zero or the chart is not supported according to Supported Charts List, this method will do nothing. NOTE: This method is now obsolete. Instead, please use ToImage(string,ImageOrPrintOptions) method with specified quality. This method will be removed 12 months later since March 2025. Aspose apologizes for any inconvenience you may have experienced.imageFile - The image file name with full path.jpegQuality - Jpeg quality.public void toPdf(java.lang.String fileName)
fileName - the pdf file name with full pathpublic void toPdf(java.lang.String fileName,
float desiredPageWidth,
float desiredPageHeight,
int hAlignmentType,
int vAlignmentType)
fileName - the pdf file name with full pathdesiredPageWidth - The desired page width in inches.desiredPageHeight - The desired page height in inches.hAlignmentType - PageLayoutAlignmentType. The chart horizontal alignment type in the output page.vAlignmentType - PageLayoutAlignmentType. The chart vertical alignment type in the output page.public void toPdf(java.io.OutputStream stream)
stream - The output stream.public void toPdf(java.io.OutputStream stream,
float desiredPageWidth,
float desiredPageHeight,
int hAlignmentType,
int vAlignmentType)
stream - The output stream.desiredPageWidth - The desired page width in inches.desiredPageHeight - The desired page height in inches.hAlignmentType - PageLayoutAlignmentType. The chart horizontal alignment type in the output page.vAlignmentType - PageLayoutAlignmentType. The chart vertical alignment type in the output page.public void toImage(java.lang.String imageFile,
ImageOrPrintOptions options)
Remarks
The format of the image is specified by using the extension of the file name. For example, if you specify "myfile.png", then the image will be saved in the PNG format. The following file extensions are recognized: .bmp, .gif, .png, .jpg, .jpeg, .tiff, .tif, .emf.
If the width or height is zero or the chart is not supported according to Supported Charts List, this method will do nothing. Please refer to Supported Charts List for more details.Example
Saves to Tiff with 300 dpi and CCITT4 compression.
ImageOrPrintOptions options = new ImageOrPrintOptions();
options.setHorizontalResolution(300);
options.setVerticalResolution(300);
options.setTiffCompression(TiffCompression.COMPRESSION_CCITT_4);
Workbook book = new Workbook("test.xls");
book.getWorksheets().get(0).getCharts().get(0).toImage("chart.Tiff", options);
imageFile - The image file name with full path.options - Additional image creation optionspublic void toImage(java.io.OutputStream stream,
ImageOrPrintOptions options)
Remarks
The format of the image is specified by using options.ImageFormat.
The following formats are supported:
ImageFormat.Bmp, ImageFormat.Gif, ImageFormat.Png, ImageFormat.Jpeg, ImageFormat.Tiff, ImageFormat.Emf.
stream - The output stream.options - Additional image creation optionspublic int[] getActualChartSize()
Remarks
NOTE: This member is now obsolete. Instead, please use Chart.getActualSize() method. This property will be removed 12 months later since July 2022. Aspose apologizes for any inconvenience you may have experienced.public int[] getActualSize()
public int getPlacement()
See PlacementType.
public void setPlacement(int value)
See PlacementType.
public PageSetup getPageSetup()
public ChartShape getChartShape()
Remarks
NOTE: This member is now obsolete. Instead, please use Aspose.Cells.Charts.Chart.ChartObject property. This property will be removed 12 months later since JANUARY 2012. Aspose apologizes for any inconvenience you may have experienced.public boolean hasAxis(int aixsType,
boolean isPrimary)
Remarks
Normally, Pie, PieExploded, PiePie,PieBar, Pie3D, Pie3DExploded,Doughnut, DoughnutExploded is no axis.public boolean switchRowColumn()
public java.lang.String getChartDataRange()
Remarks
Only supports range.public void setChartDataRange(java.lang.String area,
boolean isVertical)
area - Specifies values from which to plot the data seriesisVertical - Specifies whether to plot the series from a range of cell values by row or by column.public Line getLine()
See Also:
Aspose.Cells Documentation - the home page for the Aspose.Cells Product Documentation.
Aspose.Cells Support Forum - our preferred method of support.
We guarantee a prompt response to any inquiry!
© Aspose Pty Ltd 2003-2025. All Rights Reserved.