public class Chart
Example:
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.getNSeries().add("B2:B4", true);
chart.getNSeries().setCategoryData("A2:A4");
Series aSeries = chart.getNSeries().get(0);
aSeries.setName("=B1");
chart.setShowLegend(true);
chart.getTitle().setText("Income Analysis");
Property Getters/Setters Summary | ||
---|---|---|
java.awt.Dimension | getActualChartSize() | |
Gets actual size of chart
|
||
boolean | getAutoScaling() | |
void | setAutoScaling(booleanvalue) | |
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. | ||
Walls | getBackWall() | |
Returns a |
||
Axis | getCategoryAxis() | |
Gets the chart's X axis.
|
||
ChartArea | getChartArea() | |
Gets the chart area in the worksheet
|
||
ChartDataTable | getChartDataTable() | |
Represents the chart data table.
|
||
ChartShape | getChartObject() | |
Represents the chartShape;
|
||
ChartShape | getChartShape() | |
Represents the chartShape;
|
||
int | getDepthPercent() | |
void | setDepthPercent(intvalue) | |
Represents the depth of a 3-D chart as a percentage of the chart width (between 20 and 2000 percent). | ||
int | getElevation() | |
void | setElevation(intvalue) | |
Represents the elevation of the 3-D chart view, in degrees. | ||
int | getFirstSliceAngle() | |
void | setFirstSliceAngle(intvalue) | |
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 | getFloor() | |
Returns a |
||
int | getGapDepth() | |
void | setGapDepth(intvalue) | |
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. | ||
int | getGapWidth() | |
void | setGapWidth(intvalue) | |
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. | ||
int | getHeightPercent() | |
void | setHeightPercent(intvalue) | |
Returns or sets the height of a 3-D chart as a percentage of the chart width (between 5 and 500 percent). | ||
boolean | getHidePivotFieldButtons() | |
void | setHidePivotFieldButtons(booleanvalue) | |
Indicates whether hide the pivot chart field buttons only when the chart is PivotChart | ||
boolean | getIs3D() | |
Indicates whether the chart is a 3d chart.
|
||
boolean | isRectangularCornered() | |
void | setRectangularCornered(booleanvalue) | |
Gets or sets a value indicating whether the chart area is rectangular cornered. Default is true. | ||
Legend | getLegend() | |
Gets the chart legend.
|
||
Line | getLine() | |
Gets the line.
|
||
java.lang.String | getName() | |
void | setName(java.lang.Stringvalue) | |
Gets and sets the name of the chart. | ||
SeriesCollection | getNSeries() | |
Gets a |
||
PageSetup | getPageSetup() | |
Represents the page setup description in this chart.
|
||
short | getPerspective() | |
void | setPerspective(shortvalue) | |
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 | getPivotOptions() | |
Specifies the pivot controls that appear on the chart
|
||
java.lang.String | getPivotSource() | |
void | setPivotSource(java.lang.Stringvalue) | |
The source is the data of the pivotTable. If PivotSource is not empty ,the chart is PivotChart. | ||
int | getPlacement() | |
void | setPlacement(intvalue) | |
Represents the way the chart is attached to the cells below it. The value of the property is PlacementType integer constant. | ||
PlotArea | getPlotArea() | |
Gets the chart's plot area which includes axis tick lables.
|
||
ChartFrame | getPlotAreaWithoutTickLabels() | |
Gets the chart's plot area which does not inculde axis tick lables.
|
||
int | getPlotEmptyCellsType() | |
void | setPlotEmptyCellsType(intvalue) | |
Gets and sets how to plot the empty cells. The value of the property is PlotEmptyCellsType integer constant. | ||
boolean | getPlotVisibleCells() | |
void | setPlotVisibleCells(booleanvalue) | |
Indicates whether only plot visible cells. | ||
int | getPrintSize() | |
void | setPrintSize(intvalue) | |
Gets and sets the printed chart size. The value of the property is PrintSizeType integer constant. | ||
boolean | getRightAngleAxes() | |
void | setRightAngleAxes(booleanvalue) | |
True if the chart axes are at right angles.Applies only for 3-D charts(except Column3D and 3-D Pie Charts). | ||
int | getRotationAngle() | |
void | setRotationAngle(intvalue) | |
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() | |
void | setShowDataTable(booleanvalue) | |
Gets or sets a value indicating whether the chart displays a data table. | ||
boolean | getShowLegend() | |
void | setShowLegend(booleanvalue) | |
Gets or sets a value indicating whether the chart legend will be displayed. Default is true. | ||
Walls | getSideWall() | |
Returns a |
||
boolean | getSizeWithWindow() | |
void | setSizeWithWindow(booleanvalue) | |
True if Microsoft Excel resizes the chart to match the size of the chart sheet window. | ||
int | getStyle() | |
void | setStyle(intvalue) | |
Gets and sets the builtin style. | ||
Title | getSubTitle() | |
Gets the chart's sub-title.
Only for ODS format file.
|
||
Title | getTitle() | |
Gets the chart's title.
|
||
int | getType() | |
void | setType(intvalue) | |
Gets or sets a chart's type. The value of the property is ChartType integer constant. | ||
Axis | getValueAxis() | |
Gets the chart's Y axis.
|
||
Walls | getWalls() | |
Returns a |
||
boolean | getWallsAndGridlines2D() | |
void | setWallsAndGridlines2D(booleanvalue) | |
True if gridlines are drawn two-dimensionally on a 3-D chart. | ||
Worksheet | getWorksheet() | |
Gets the worksheet which contains this chart.
|
Method Summary | ||
---|---|---|
void | calculate() | |
Calcuate the custom position of plot area, axises if the position of them are auto assigned.
|
||
boolean | hasAxis(int aixsType, boolean isPrimary) | |
Returns which axes exist on the chart.
|
||
boolean | isChartDataChanged() | |
Detects if a chart's data source has changed.
|
||
void | move(int upperLeftRow, int upperLeftColumn, int lowerRightRow, int lowerRightColumn) | |
Moves the chart to a specified location.
|
||
void | refreshPivotData() | |
Refreshes pivot chart's data from it's pivot data source.
|
||
void | setChartDataRange(java.lang.String area, boolean isVertical) | |
Specifies data range for a chart.
|
||
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.
The extension of the file name determines the format of the image.
|
||
void | toImage(java.lang.String imageFile, ImageFormat imageFormat) | |
Creates the chart image and saves it to a file in the specified format.
|
||
void | toImage(java.lang.String imageFile, ImageOrPrintOptions options) | |
Creates the chart image and saves it to a file.
The extension of the file name determines the format of the image.
|
||
void | toImage(java.lang.String imageFile, long jpegQuality) | |
Creates the chart image and saves it to a file in the Jpeg format.
|
||
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() / public void setStyle(int value)
public ChartShape getChartObject()
public boolean getHidePivotFieldButtons() / public void setHidePivotFieldButtons(boolean value)
public PivotOptions getPivotOptions()
public java.lang.String getPivotSource() / public void setPivotSource(java.lang.String value)
public int getPlotEmptyCellsType() / public void setPlotEmptyCellsType(int value)
public boolean getPlotVisibleCells() / public void setPlotVisibleCells(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() / public void setPrintSize(int value)
public int getType() / public void setType(int value)
public SeriesCollection getNSeries()
public Title getTitle()
public Title getSubTitle()
public ChartFrame getPlotAreaWithoutTickLabels()
public PlotArea getPlotArea()
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 Floor getFloor()
public Walls getWalls()
public Walls getBackWall()
public Walls getSideWall()
public boolean getWallsAndGridlines2D() / public void setWallsAndGridlines2D(boolean value)
public int getRotationAngle() / public void setRotationAngle(int value)
public int getElevation() / public void setElevation(int value)
public boolean getRightAngleAxes() / public void setRightAngleAxes(boolean value)
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 java.awt.Dimension getActualChartSize()
public int getPlacement() / public void setPlacement(int value)
public PageSetup getPageSetup()
public ChartShape getChartShape()
public Line getLine()
public void toImage(java.lang.String imageFile) throws java.lang.Exception
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.imageFile
- The image file name with full path.public void toImage(java.lang.String imageFile, ImageFormat imageFormat) throws java.lang.Exception
The format of the image is specified by using imageFormat
.
The following formats are supported:
ImageFormat.Bmp, ImageFormat.Gif, ImageFormat.Png, ImageFormat.Jpeg, ImageFormat.Tiff, ImageFormat.Emf.
imageFile
- The image file name with full path.imageFormat
- The format in which to save the image.public void toImage(java.lang.String imageFile, long jpegQuality) throws java.lang.Exception
imageFile
- The image file name with full path.jpegQuality
- Jpeg quality.public void toPdf(java.lang.String fileName) throws java.lang.Exception
fileName
- the pdf file name with full pathpublic void toPdf(java.lang.String fileName, float desiredPageWidth, float desiredPageHeight, int hAlignmentType, int vAlignmentType) throws java.lang.Exception
fileName
- the pdf file name with full pathdesiredPageWidth
- The desired page width in inches.desiredPageHeight
- The desired page height in inches.hAlignmentType
- A vAlignmentType
- A public void toPdf(java.io.OutputStream stream) throws java.lang.Exception
stream
- The output stream.public void toPdf(java.io.OutputStream stream, float desiredPageWidth, float desiredPageHeight, int hAlignmentType, int vAlignmentType) throws java.lang.Exception
stream
- The output stream.desiredPageWidth
- The desired page width in inches.desiredPageHeight
- The desired page height in inches.hAlignmentType
- A vAlignmentType
- A public void toImage(java.lang.String imageFile, ImageOrPrintOptions options) throws java.lang.Exception
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.imageFile
- The image file name with full path.options
- Addtional image creation optionsExample:
ImageOrPrintOptions options = new ImageOrPrintOptions(); options.setHorizontalResolution(300); options.setVerticalResolution(300); Workbook book = new Workbook("c:\\test.xls"); book.getWorksheets().get(0).getCharts().get(0).toImage("c:\\chart.png", options);
public void toImage(java.io.OutputStream stream, ImageOrPrintOptions options) throws java.lang.Exception
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
- Addtional image creation optionspublic boolean hasAxis(int aixsType, boolean isPrimary)
aixsType
- A AxisType value.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 boolean isChartDataChanged() throws java.lang.Exception
public void refreshPivotData()
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 void calculate() throws java.lang.Exception