public class Legend extends ChartTextFrame
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.setChartDataRange("A1:B4", true);
//Set Legend's width and height
Legend 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(LegendPositionType.LEFT);
| Modifier and Type | Method and Description |
|---|---|
LegendEntryCollection |
getLegendEntries()
Gets a collection of all the LegendEntry objects in the specified chart legend.
|
java.util.ArrayList |
getLegendEntriesLabels()
Deprecated.
Use Legend.GetLegendLabels method, instead.
|
java.lang.String[] |
getLegendLabels()
Gets the labels of the legend entries after call Chart.Calculate() method.
|
int |
getPosition()
Gets the legend position type.
|
boolean |
isOverLay()
Gets whether showing the legend without overlapping the chart.
|
void |
setOverLay(boolean value)
Sets whether showing the legend without overlapping the chart.
|
void |
setPosition(int value)
Sets the legend position type.
|
characters, getDirectionType, getLinkedSource, getReadingOrder, getRotationAngle, getText, getTextDirection, getTextHorizontalAlignment, getTextVerticalAlignment, isAutomaticRotation, isAutoText, isDeleted, isResizeShapeToFitText, isTextWrapped, setAutoText, setDeleted, setDirectionType, setLinkedSource, setReadingOrder, setResizeShapeToFitText, setRotationAngle, setText, setTextDirection, setTextHorizontalAlignment, setTextVerticalAlignment, setTextWrappedgetArea, getAutoScaleFont, getBackground, getBackgroundMode, getBorder, getChart, getDefaultHeight, getDefaultHeightRatioToChart, getDefaultWidth, getDefaultWidthRatioToChart, getDefaultX, getDefaultXRatioToChart, getDefaultY, getDefaultYRatioToChart, getFont, getHeight, getHeightPixel, getHeightRatioToChart, getShadow, getShapeProperties, getTextFont, getTextOptions, getWidth, getWidthPixel, getWidthRatioToChart, getX, getXPixel, getXRatioToChart, getY, getYPixel, getYRatioToChart, isAutomaticSize, isDefaultPosBeSet, isInnerMode, setAutomaticSize, setAutoScaleFont, setBackground, setBackgroundMode, setHeight, setHeightPixel, setHeightRatioToChart, setInnerMode, setPositionAuto, setShadow, setWidth, setWidthPixel, setWidthRatioToChart, setX, setXPixel, setXRatioToChart, setY, setYPixel, setYRatioToChartpublic int getPosition()
See LegendPositionType.
Remarks
public void setPosition(int value)
See LegendPositionType.
Remarks
public LegendEntryCollection getLegendEntries()
public java.lang.String[] getLegendLabels()
public java.util.ArrayList getLegendEntriesLabels()
Remarks
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.public boolean isOverLay()
public void setOverLay(boolean value)
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.