aspose.cells

Class Legend

Encapsulates the object that represents the chart legend.

Example:

$workbook = new cells\Workbook();
$worksheet = $workbook->getWorksheets()->get(0);
$cells = $worksheet->getCells();
$cells->get("A1")->putValue(50);
$cells->get("A2")->putValue(100);
$cells->get("A3")->putValue(150);
$cells->get("A4")->putValue(200);
$cells->get("B1")->putValue(60);
$cells->get("B2")->putValue(32);
$cells->get("B3")->putValue(50);
$cells->get("B4")->putValue(40);
$cells->get("C1")->putValue("Q1");
$cells->get("C2")->putValue("Q2");
$cells->get("C3")->putValue("Y1");
$cells->get("C4")->putValue("Y2");
//Adding a chart to the worksheet
$chartIndex = $worksheet->getCharts()->add(cells\ChartType::COLUMN, 5, 0, 15, 5);
//Accessing the instance of the newly added chart
$chart = $worksheet->getCharts()->get($chartIndex);
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
$chart->getNSeries()->add("A1:B4", true);
//Setting the data source for the category data of NSeries
$chart->getNSeries()->setCategoryData("C1:C4");

$legend = $chart->getLegend();
//Legend is at right side of chart by default
//If the legend is at left or right side of the chart, setting Legend->X property will not take effect
//If the legend is at top or bottom side of the chart, setting Legend->Y property will not take effect
$legend->setY(1500);
$legend->setWidth(50);
$legend->setHeight(50);
//Set legend's position
$legend->setPosition(cells\LegendPositionType::LEFT);

Property Getters/Setters Summary
functiongetArea()
Gets the area.
functiongetAutoScaleFont()
function
           True if the text in the object changes font size when the object size changes. The default value is True.
functiongetBackground()
function
           Gets and sets the display mode of the background The value of the property is BackgroundMode integer constant.
functiongetBackgroundMode()
function
           Gets and sets the display mode of the background The value of the property is BackgroundMode integer constant.
functiongetBorder()
Gets the Line.
functiongetChart()
Gets the chart to which this object belongs.
functiongetDefaultHeight()
Represents height of default position
functiongetDefaultWidth()
Represents width of default position
functiongetDefaultX()
Represents x of default position
functiongetDefaultY()
Represents y of default position
functiongetDirectionType()
function
           Gets and sets the direction of text. The value of the property is ChartTextDirectionType integer constant.
functiongetFont()
Gets a Font object of the specified ChartFrame object.
functiongetHeight()
function
setHeight(value)
           Gets or sets the height of frame in units of 1/4000 of the chart area.
functionisAutomaticRotation()
Indicates whether the text of the chart is automatically rotated.
functionisAutomaticSize()
function
           Indicates whether the chart frame is automatic sized.
functionisAutoText()
function
           Indicates the text is auto generated.
functionisDefaultPosBeSet()
Indicates whether default position(DefaultX, DefaultY, DefaultWidth and DefaultHeight) are set.
functionisDeleted()
function
setDeleted(value)
           Indicates whether this data labels is deleted.
functionisInnerMode()
function
           Indicates whether the size of the plot area size includes the tick marks, and the axis labels. False specifies that the size shall determine the size of the plot area, the tick marks, and the axis labels.
functionisOverLay()
function
setOverLay(value)
           Gets or sets whether showing the legend without overlapping the chart.
functionisResizeShapeToFitText()
function
           Gets or sets whether a shape should be auto-fit to fully contain the text described within it. Auto-fitting is when text within a shape is scaled in order to contain all the text inside.
functionisTextWrapped()
function
           Gets or sets a value indicating whether the text is wrapped.
functiongetLegendEntries()
Gets a collection of all the LegendEntry objects in the specified chart legend. Setting the legend entries of the surface chart is not supported. So it will return null if the chart type is surface chart type.
functiongetLegendEntriesLabels()
Gets the labels of the legend entries after call Chart.Calculate() method.
functiongetLinkedSource()
function
           Gets and sets a reference to the worksheet.
functiongetPosition()
function
           Gets or sets the legend position type. The value of the property is LegendPositionType integer constant.
functiongetReadingOrder()
function
           Represents text reading order. The value of the property is TextDirectionType integer constant.
functiongetRotationAngle()
function
           Represents text rotation angle.
functiongetShadow()
function
setShadow(value)
           True if the frame has a shadow.
functiongetShapeProperties()
Gets the ShapeProperties object.
functiongetText()
function
setText(value)
           Gets or sets the text of a frame's title.
functiongetTextDirection()
function
           Represents text reading order. The value of the property is TextDirectionType integer constant.
functiongetTextFont()
Gets a Font object of the specified ChartFrame object.
functiongetTextHorizontalAlignment()
function
           Gets and sets the text horizontal alignment. The value of the property is TextAlignmentType integer constant.
functiongetTextOptions()
Gets and sets the options of the text.
functiongetTextVerticalAlignment()
function
           Gets or sets the text vertical alignment of text. The value of the property is TextAlignmentType integer constant.
functiongetWidth()
function
setWidth(value)
           Gets or sets the width of frame in units of 1/4000 of the chart area.
functiongetX()
function
setX(value)
           Gets or sets the x coordinate of the upper left corner in units of 1/4000 of the chart area.
functiongetY()
function
setY(value)
           Gets or sets the y coordinate of the upper left corner in units of 1/4000 of the chart area.
 
Method Summary
functioncharacters(startIndex, length)
Returns a Characters object that represents a range of characters within the text.
functiongetLegendLabels()
Gets the labels of the legend entries after call Chart.Calculate() method.
functionsetPositionAuto()
Set position of the frame to automatic
 

    • Property Getters/Setters Detail

      • getPosition/setPosition : Number 

        function getPosition() / function setPosition(value)
        
        Gets or sets the legend position type. The value of the property is LegendPositionType integer constant.
        Default position is right.

        If the legend is at left or right side of the chart, setting Legend.X property will not take effect.

        If the legend is at top or bottom side of the chart, setting Legend.Y property will not take effect.
      • getLegendEntries : LegendEntryCollection 

        function getLegendEntries()
        
        Gets a collection of all the LegendEntry objects in the specified chart legend. Setting the legend entries of the surface chart is not supported. So it will return null if the chart type is surface chart type.
      • getLegendEntriesLabels : ArrayList 

        function getLegendEntriesLabels()
        
        Gets the labels of the legend entries after call Chart.Calculate() method. NOTE: This member is now obsolete. Instead, please use Legend.GetLegendLabels method. This property will be removed 12 months later since November 2023. Aspose apologizes for any inconvenience you may have experienced.
      • isOverLay/setOverLay : boolean 

        function isOverLay() / function setOverLay(value)
        
        Gets or sets whether showing the legend without overlapping the chart.
      • isAutoText/setAutoText : boolean 

        function isAutoText() / function setAutoText(value)
        
        Indicates the text is auto generated.
      • isDeleted/setDeleted : boolean 

        function isDeleted() / function setDeleted(value)
        
        Indicates whether this data labels is deleted.
      • getTextHorizontalAlignment/setTextHorizontalAlignment : Number 

        function getTextHorizontalAlignment() / function setTextHorizontalAlignment(value)
        
        Gets and sets the text horizontal alignment. The value of the property is TextAlignmentType integer constant.
      • getTextVerticalAlignment/setTextVerticalAlignment : Number 

        function getTextVerticalAlignment() / function setTextVerticalAlignment(value)
        
        Gets or sets the text vertical alignment of text. The value of the property is TextAlignmentType integer constant.
      • getRotationAngle/setRotationAngle : Number 

        function getRotationAngle() / function setRotationAngle(value)
        
        Represents text rotation angle.
        0: Not rotated.

        255: Top to Bottom.

        -90: Downward.

        90: Upward.
      • isAutomaticRotation : boolean 

        function isAutomaticRotation()
        
        Indicates whether the text of the chart is automatically rotated.
      • getText/setText : String 

        function getText() / function setText(value)
        
        Gets or sets the text of a frame's title.
      • getLinkedSource/setLinkedSource : String 

        function getLinkedSource() / function setLinkedSource(value)
        
        Gets and sets a reference to the worksheet.
      • getTextDirection/setTextDirection : Number 

        function getTextDirection() / function setTextDirection(value)
        
        Represents text reading order. The value of the property is TextDirectionType integer constant.NOTE: This member is now obsolete. Instead, please use ChartTextFrame.ReadingOrder property. This property will be removed 12 months later since March 2020. Aspose apologizes for any inconvenience you may have experienced.
      • getReadingOrder/setReadingOrder : Number 

        function getReadingOrder() / function setReadingOrder(value)
        
        Represents text reading order. The value of the property is TextDirectionType integer constant.
      • getDirectionType/setDirectionType : Number 

        function getDirectionType() / function setDirectionType(value)
        
        Gets and sets the direction of text. The value of the property is ChartTextDirectionType integer constant.
      • isTextWrapped/setTextWrapped : boolean 

        function isTextWrapped() / function setTextWrapped(value)
        
        Gets or sets a value indicating whether the text is wrapped.
      • isResizeShapeToFitText/setResizeShapeToFitText : boolean 

        function isResizeShapeToFitText() / function setResizeShapeToFitText(value)
        
        Gets or sets whether a shape should be auto-fit to fully contain the text described within it. Auto-fitting is when text within a shape is scaled in order to contain all the text inside.
      • isInnerMode/setInnerMode : boolean 

        function isInnerMode() / function setInnerMode(value)
        
        Indicates whether the size of the plot area size includes the tick marks, and the axis labels. False specifies that the size shall determine the size of the plot area, the tick marks, and the axis labels. Only for Xlsx file.
      • getChart : Chart 

        function getChart()
        
        Gets the chart to which this object belongs.
      • getBorder : Line 

        function getBorder()
        
        Gets the Line.
      • getArea : Area 

        function getArea()
        
        Gets the area.
      • getTextFont : Font 

        function getTextFont()
        
        Gets a Font object of the specified ChartFrame object. NOTE: This member is now obsolete. Instead, please use ChartFrame.Font property. This property will be removed 12 months later since JANUARY 2012. Aspose apologizes for any inconvenience you may have experienced.
      • getTextOptions : TextOptions 

        function getTextOptions()
        
        Gets and sets the options of the text.
      • getFont : Font 

        function getFont()
        
        Gets a Font object of the specified ChartFrame object.
      • getAutoScaleFont/setAutoScaleFont : boolean 

        function getAutoScaleFont() / function setAutoScaleFont(value)
        
        True if the text in the object changes font size when the object size changes. The default value is True.
      • getBackgroundMode/setBackgroundMode : Number 

        function getBackgroundMode() / function setBackgroundMode(value)
        
        Gets and sets the display mode of the background The value of the property is BackgroundMode integer constant.
      • getBackground/setBackground : Number 

        function getBackground() / function setBackground(value)
        
        Gets and sets the display mode of the background The value of the property is BackgroundMode integer constant.NOTE: This member is now obsolete. Instead, please use ChartFrame.BackgroundMode property. This property will be removed 12 months later since JANUARY 2012. Aspose apologizes for any inconvenience you may have experienced.
      • isAutomaticSize/setAutomaticSize : boolean 

        function isAutomaticSize() / function setAutomaticSize(value)
        
        Indicates whether the chart frame is automatic sized.
      • getX/setX : Number 

        function getX() / function setX(value)
        
        Gets or sets the x coordinate of the upper left corner in units of 1/4000 of the chart area. How to convert units of 1/4000 to pixels? X In Pixels = X * Chart.ChartObject.Width / 4000;
      • getY/setY : Number 

        function getY() / function setY(value)
        
        Gets or sets the y coordinate of the upper left corner in units of 1/4000 of the chart area. How to convert units of 1/4000 to pixels? Y In Pixels = Y * Chart.ChartObject.Height / 4000;
      • getHeight/setHeight : Number 

        function getHeight() / function setHeight(value)
        
        Gets or sets the height of frame in units of 1/4000 of the chart area. How to convert units of 1/4000 to pixels? Height In Pixels = Y * Chart.ChartObject.Height / 4000;
      • getWidth/setWidth : Number 

        function getWidth() / function setWidth(value)
        
        Gets or sets the width of frame in units of 1/4000 of the chart area. How to convert units of 1/4000 to pixels? Width In Pixels = Width * Chart.ChartObject.Height / 4000;
      • getShadow/setShadow : boolean 

        function getShadow() / function setShadow(value)
        
        True if the frame has a shadow.
      • isDefaultPosBeSet : boolean 

        function isDefaultPosBeSet()
        
        Indicates whether default position(DefaultX, DefaultY, DefaultWidth and DefaultHeight) are set.
      • getDefaultX : Number 

        function getDefaultX()
        
        Represents x of default position
      • getDefaultY : Number 

        function getDefaultY()
        
        Represents y of default position
      • getDefaultWidth : Number 

        function getDefaultWidth()
        
        Represents width of default position
      • getDefaultHeight : Number 

        function getDefaultHeight()
        
        Represents height of default position
    • Method Detail

      • getLegendLabels

        function getLegendLabels()
        Gets the labels of the legend entries after call Chart.Calculate() method.
      • characters

        function characters(startIndex, length)
        Returns a Characters object that represents a range of characters within the text.
        Parameters:
        startIndex: Number - The index of the start of the character.
        length: Number - The number of characters.
        Returns:
        Characters object.
      • setPositionAuto

        function setPositionAuto()
        Set position of the frame to automatic