aspose.cells

Class Chart

Encapsulates the object that represents a single Excel chart.

Example:

$workbook = new cells\Workbook();
$sheet = $workbook->getWorksheets()->get(0);
$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);
$chartIndex = $sheet->getCharts()->add(cells\ChartType::COLUMN, 9, 9, 21, 15);
$chart = $sheet->getCharts()->get($chartIndex);
$chart->getNSeries()->add("B2:B4", true);
$chart->getNSeries()->setCategoryData("A2:A4");
$aSeries = $chart->getNSeries()->get(0);
$aSeries->setName("=B1");
$chart->setShowLegend(true);
$chart->getTitle()->setText("Income Analysis");

Property Getters/Setters Summary
functiongetActualChartSize()
Gets actual size of chart
functiongetAutoScaling()
function
           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.
functiongetBackWall()
Returns a Walls object that represents the back wall of a 3-D chart.
functiongetCategoryAxis()
Gets the chart's X axis.
functiongetChartArea()
Gets the chart area in the worksheet
functiongetChartDataTable()
Represents the chart data table.
functiongetChartObject()
Represents the chartShape;
functiongetChartShape()
Represents the chartShape;
functiongetDepthPercent()
function
           Represents the depth of a 3-D chart as a percentage of the chart width (between 20 and 2000 percent).
functiongetDisplayNaAsBlank()
function
           Indicates whether displaying #N/A as blank value.
functiongetElevation()
function
           Represents the elevation of the 3-D chart view, in degrees.
functiongetFirstSliceAngle()
function
           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.
functiongetFloor()
Returns a Floor object that represents the walls of a 3-D chart.
functiongetGapDepth()
function
           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.
functiongetGapWidth()
function
           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.
functiongetHeightPercent()
function
           Returns or sets the height of a 3-D chart as a percentage of the chart width (between 5 and 500 percent).
functiongetHidePivotFieldButtons()
function
           Indicates whether hide the pivot chart field buttons only when the chart is PivotChart
functiongetIs3D()
Indicates whether the chart is a 3d chart.
functionisRectangularCornered()
function
           Gets or sets a value indicating whether the chart area is rectangular cornered. Default is true.
functiongetLegend()
Gets the chart legend.
functiongetLine()
Gets the line.
functiongetName()
function
setName(value)
           Gets and sets the name of the chart.
functiongetNSeries()
Gets a SeriesCollection collection representing the data series in the chart.
functiongetPageSetup()
Represents the page setup description in this chart.
functiongetPerspective()
function
           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.
functiongetPivotOptions()
Specifies the pivot controls that appear on the chart
functiongetPivotSource()
function
           The source is the data of the pivotTable. If PivotSource is not empty ,the chart is PivotChart.
functiongetPlacement()
function
           Represents the way the chart is attached to the cells below it. The value of the property is PlacementType integer constant.
functiongetPlotArea()
Gets the chart's plot area which includes axis tick labels.
functiongetPlotBy()
Gets and sets whether plot by row or column. The value of the property is PlotDataByType integer constant.
functiongetPlotEmptyCellsType()
function
           Gets and sets how to plot the empty cells. The value of the property is PlotEmptyCellsType integer constant.
functiongetPlotVisibleCells()
function
           Indicates whether only plot visible cells.
functiongetPrintSize()
function
           Gets and sets the printed chart size. The value of the property is PrintSizeType integer constant.
functiongetRightAngleAxes()
function
           True if the chart axes are at right angles. Applies only for 3-D charts(except Column3D and 3-D Pie Charts).
functiongetRotationAngle()
function
           Represents the rotation of the 3-D chart view (the rotation of the plot area around the z-axis, in degrees).
functiongetSecondCategoryAxis()
Gets the chart's second X axis.
functiongetSecondValueAxis()
Gets the chart's second Y axis.
functiongetSeriesAxis()
Gets the chart's series axis.
functiongetShapes()
Returns all drawing shapes in this chart.
functiongetShowDataTable()
function
           Gets or sets a value indicating whether the chart displays a data table.
functiongetShowLegend()
function
           Gets or sets a value indicating whether the chart legend will be displayed. Default is true.
functiongetSideWall()
Returns a Walls object that represents the side wall of a 3-D chart.
functiongetSizeWithWindow()
function
           True if Microsoft Excel resizes the chart to match the size of the chart sheet window.
functiongetStyle()
function
setStyle(value)
           Gets and sets the builtin style.
functiongetSubTitle()
Gets the chart's sub-title. Only for ODS format file.
functiongetTitle()
Gets the chart's title.
functiongetType()
function
setType(value)
           Gets or sets a chart's type. The value of the property is ChartType integer constant.
functiongetValueAxis()
Gets the chart's Y axis.
functiongetWalls()
Returns a Walls object that represents the walls of a 3-D chart.
functiongetWallsAndGridlines2D()
function
           True if gridlines are drawn two-dimensionally on a 3-D chart.
functiongetWorksheet()
Gets the worksheet which contains this chart.
 
Method Summary
functioncalculate()
Calculates the custom position of plot area, axes if the position of them are auto assigned.
functiongetChartDataRange()
Gets the data source range of the chart .
functionhasAxis(aixsType, isPrimary)
Returns which axes exist on the chart.
functionisChartDataChanged()
Detects if a chart's data source has changed.
functionmove(upperLeftRow, upperLeftColumn, lowerRightRow, lowerRightColumn)
Moves the chart to a specified location.
functionrefreshPivotData()
Refreshes pivot chart's data from it's pivot data source.
functionsetChartDataRange(area, isVertical)
Specifies data range for a chart.
functionswitchRowColumn()
Switches row/column.
functiontoImage(imageFile)
Creates the chart image and saves it to a file. The extension of the file name determines the format of the image.
functiontoImage(imageFile, imageFormat)
Creates the chart image and saves it to a file in the specified format.
functiontoImage(imageFile, options)
Creates the chart image and saves it to a file. The extension of the file name determines the format of the image.
functiontoImage(imageFile, jpegQuality)
Creates the chart image and saves it to a file in the Jpeg format.
functiontoPdf(fileName)
Saves the chart to a pdf file.
functiontoPdf(fileName, desiredPageWidth, desiredPageHeight, hAlignmentType, vAlignmentType)
Saves the chart to a pdf file.
 

    • Property Getters/Setters Detail

      • getStyle/setStyle : Number 

        function getStyle() / function setStyle(value)
        
        Gets and sets the builtin style. It should be between 1 and 48. Return -1 if it's not be set.
      • getChartObject : ChartShape 

        function getChartObject()
        
        Represents the chartShape;
      • getHidePivotFieldButtons/setHidePivotFieldButtons : boolean 

        function getHidePivotFieldButtons() / function setHidePivotFieldButtons(value)
        
        Indicates whether hide the pivot chart field buttons only when the chart is PivotChart
      • getPivotOptions : PivotOptions 

        function getPivotOptions()
        
        Specifies the pivot controls that appear on the chart
      • getPivotSource/setPivotSource : String 

        function getPivotSource() / function setPivotSource(value)
        
        The source is the data of the pivotTable. If PivotSource is not empty ,the chart is PivotChart. 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.
      • getPlotBy : Number 

        function getPlotBy()
        
        Gets and sets whether plot by row or column. The value of the property is PlotDataByType integer constant.
      • getPlotEmptyCellsType/setPlotEmptyCellsType : Number 

        function getPlotEmptyCellsType() / function setPlotEmptyCellsType(value)
        
        Gets and sets how to plot the empty cells. The value of the property is PlotEmptyCellsType integer constant.
      • getPlotVisibleCells/setPlotVisibleCells : boolean 

        function getPlotVisibleCells() / function setPlotVisibleCells(value)
        
        Indicates whether only plot visible cells.
      • getDisplayNaAsBlank/setDisplayNaAsBlank : boolean 

        function getDisplayNaAsBlank() / function setDisplayNaAsBlank(value)
        
        Indicates whether displaying #N/A as blank value.
      • getName/setName : String 

        function getName() / function setName(value)
        
        Gets and sets the name of the chart.
      • getSizeWithWindow/setSizeWithWindow : boolean 

        function getSizeWithWindow() / function setSizeWithWindow(value)
        
        True if Microsoft Excel resizes the chart to match the size of the chart sheet window.
      • getWorksheet : Worksheet 

        function getWorksheet()
        
        Gets the worksheet which contains this chart.
      • getShapes : ShapeCollection 

        function getShapes()
        
        Returns all drawing shapes in this chart.
      • getPrintSize/setPrintSize : Number 

        function getPrintSize() / function setPrintSize(value)
        
        Gets and sets the printed chart size. The value of the property is PrintSizeType integer constant.
      • getType/setType : Number 

        function getType() / function setType(value)
        
        Gets or sets a chart's type. The value of the property is ChartType integer constant.
      • getTitle : Title 

        function getTitle()
        
        Gets the chart's title.
      • getSubTitle : Title 

        function getSubTitle()
        
        Gets the chart's sub-title. Only for ODS format file.
      • getPlotArea : PlotArea 

        function getPlotArea()
        
        Gets the chart's plot area which includes axis tick labels.
      • getChartArea : ChartArea 

        function getChartArea()
        
        Gets the chart area in the worksheet
      • getCategoryAxis : Axis 

        function getCategoryAxis()
        
        Gets the chart's X axis.
      • getValueAxis : Axis 

        function getValueAxis()
        
        Gets the chart's Y axis.
      • getSecondValueAxis : Axis 

        function getSecondValueAxis()
        
        Gets the chart's second Y axis.
      • getSecondCategoryAxis : Axis 

        function getSecondCategoryAxis()
        
        Gets the chart's second X axis.
      • getSeriesAxis : Axis 

        function getSeriesAxis()
        
        Gets the chart's series axis.
      • getLegend : Legend 

        function getLegend()
        
        Gets the chart legend.
      • getChartDataTable : ChartDataTable 

        function getChartDataTable()
        
        Represents the chart data table.
      • getShowLegend/setShowLegend : boolean 

        function getShowLegend() / function setShowLegend(value)
        
        Gets or sets a value indicating whether the chart legend will be displayed. Default is true.
      • isRectangularCornered/setRectangularCornered : boolean 

        function isRectangularCornered() / function setRectangularCornered(value)
        
        Gets or sets a value indicating whether the chart area is rectangular cornered. Default is true.
      • getShowDataTable/setShowDataTable : boolean 

        function getShowDataTable() / function setShowDataTable(value)
        
        Gets or sets a value indicating whether the chart displays a data table.
      • getFirstSliceAngle/setFirstSliceAngle : Number 

        function getFirstSliceAngle() / function setFirstSliceAngle(value)
        
        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.
      • getGapWidth/setGapWidth : Number 

        function getGapWidth() / function setGapWidth(value)
        
        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.
      • getGapDepth/setGapDepth : Number 

        function getGapDepth() / function setGapDepth(value)
        
        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.
      • getFloor : Floor 

        function getFloor()
        
        Returns a Floor object that represents the walls of a 3-D chart. This property doesn't apply to 3-D pie charts.
      • getWalls : Walls 

        function getWalls()
        
        Returns a Walls object that represents the walls of a 3-D chart. This property doesn't apply to 3-D pie charts.
      • getBackWall : Walls 

        function getBackWall()
        
        Returns a Walls object that represents the back wall of a 3-D chart.
      • getSideWall : Walls 

        function getSideWall()
        
        Returns a Walls object that represents the side wall of a 3-D chart.
      • getWallsAndGridlines2D/setWallsAndGridlines2D : boolean 

        function getWallsAndGridlines2D() / function setWallsAndGridlines2D(value)
        
        True if gridlines are drawn two-dimensionally on a 3-D chart.
      • getRotationAngle/setRotationAngle : Number 

        function getRotationAngle() / function setRotationAngle(value)
        
        Represents the rotation of the 3-D chart view (the rotation of the plot area around the z-axis, in degrees). 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.
      • getElevation/setElevation : Number 

        function getElevation() / function setElevation(value)
        
        Represents the elevation of the 3-D chart view, in degrees. 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.
      • getRightAngleAxes/setRightAngleAxes : boolean 

        function getRightAngleAxes() / function setRightAngleAxes(value)
        
        True if the chart axes are at right angles. Applies only for 3-D charts(except Column3D and 3-D Pie Charts). If this property is True, the Perspective property is ignored.
      • getAutoScaling/setAutoScaling : boolean 

        function getAutoScaling() / function setAutoScaling(value)
        
        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.
      • getHeightPercent/setHeightPercent : Number 

        function getHeightPercent() / function setHeightPercent(value)
        
        Returns or sets the height of a 3-D chart as a percentage of the chart width (between 5 and 500 percent).
      • getPerspective/setPerspective : Number 

        function getPerspective() / function setPerspective(value)
        
        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.
      • getIs3D : boolean 

        function getIs3D()
        
        Indicates whether the chart is a 3d chart.
      • getDepthPercent/setDepthPercent : Number 

        function getDepthPercent() / function setDepthPercent(value)
        
        Represents the depth of a 3-D chart as a percentage of the chart width (between 20 and 2000 percent).
      • getActualChartSize : Dimension 

        function getActualChartSize()
        
        Gets actual size of chart
      • getPlacement/setPlacement : Number 

        function getPlacement() / function setPlacement(value)
        
        Represents the way the chart is attached to the cells below it. The value of the property is PlacementType integer constant.
      • getPageSetup : PageSetup 

        function getPageSetup()
        
        Represents the page setup description in this chart.
      • getChartShape : ChartShape 

        function getChartShape()
        
        Represents the chartShape; 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.
      • getLine : Line 

        function getLine()
        
        Gets the line.
    • Method Detail

      • toImage

        function toImage(imageFile)
        Creates the chart image and saves it to a file. The extension of the file name determines the format of the image.

        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.
        Parameters:
        imageFile: String - The image file name with full path.
      • toImage

        function toImage(imageFile, imageFormat)
        Creates the chart image and saves it to a file in the specified format.

        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.

        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.
        Parameters:
        imageFile: String - The image file name with full path.
        imageFormat: ImageFormat - The format in which to save the image.
      • toImage

        function toImage(imageFile, jpegQuality)
        Creates the chart image and saves it to a file in the Jpeg format. 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.
        Parameters:
        imageFile: String - The image file name with full path.
        jpegQuality: long - Jpeg quality.
      • toPdf

        function toPdf(fileName)
        Saves the chart to a pdf file.
        Parameters:
        fileName: String - the pdf file name with full path
      • toPdf

        function toPdf(fileName, desiredPageWidth, desiredPageHeight, hAlignmentType, vAlignmentType)
        Saves the chart to a pdf file.
        Parameters:
        fileName: String - the pdf file name with full path
        desiredPageWidth: Number - The desired page width in inches.
        desiredPageHeight: Number - The desired page height in inches.
        hAlignmentType: Number - A PageLayoutAlignmentType value. The chart horizontal alignment type in the output page.
        vAlignmentType: Number - A PageLayoutAlignmentType value. The chart vertical alignment type in the output page.
      • toImage

        function toImage(imageFile, options)
        Creates the chart image and saves it to a file. The extension of the file name determines the format of the image.

        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.
        Parameters:
        imageFile: String - The image file name with full path.
        options: ImageOrPrintOptions - Additional image creation options
      • hasAxis

        function hasAxis(aixsType, isPrimary)
        Returns which axes exist on the chart. Normally, Pie, PieExploded, PiePie,PieBar, Pie3D, Pie3DExploded,Doughnut, DoughnutExploded is no axis.
        Parameters:
        aixsType - A AxisType value.
      • switchRowColumn

        function switchRowColumn()
        Switches row/column.
        Returns:
        False means switching row/column fails.
      • getChartDataRange

        function getChartDataRange()
        Gets the data source range of the chart . Only supports range.
        Returns:
        The data source.
      • setChartDataRange

        function setChartDataRange(area, isVertical)
        Specifies data range for a chart.
        Parameters:
        area: String - Specifies values from which to plot the data series
        isVertical: boolean - Specifies whether to plot the series from a range of cell values by row or by column.
      • isChartDataChanged

        function isChartDataChanged()
        Detects if a chart's data source has changed. 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.
        Returns:
        Returns true if the chart has changed otherwise returns false
      • refreshPivotData

        function refreshPivotData()
        Refreshes pivot chart's data from it's pivot data source. We will gather data from pivot data source to the pivot chart cache. This method is only used to gather all data to a pivot chart.
      • move

        function move(upperLeftRow, upperLeftColumn, lowerRightRow, lowerRightColumn)
        Moves the chart to a specified location.
        Parameters:
        upperLeftColumn: Number - Upper left column index.
        upperLeftRow: Number - Upper left row index.
        lowerRightColumn: Number - Lower right column index
        lowerRightRow: Number - Lower right row index
      • calculate

        function calculate()
        Calculates the custom position of plot area, axes if the position of them are auto assigned.