public final class LegendBox extends DockableBar
Provides access to the LegendBox object.
The statistical legend is not only used to display statistical analysis values, but also allows your end users to interact with any interactive studies applied to the chart. The supported members of this class allow you to apply visual attributes to the statistical legend.
| Constructor and Description |
|---|
LegendBox()
Constructs a newly allocated LegendBox object
|
| Modifier and Type | Method and Description |
|---|---|
ContentLayout |
getContentLayout()
Allows you to align the content for the legend box.
|
java.util.List<CustomLegendItem> |
getCustomItems()
Returns the collection of the custom items in the legend box.
|
java.awt.Font |
getFont()
Gets or sets the font of the Legend Box.
|
HighlightLegendAttributes |
getHighlight()
Returns a HighlightLegendAttributes object.
|
LegendItemAttributesCollection |
getItemAttributes()
Allows you to configure the Legend Box Items in the chart.
|
double |
getLineSpacing()
Gets or sets the space in pixels between the LegendBox items
|
int |
getMarginX()
Gets or sets a value specifying the margin width for a LegendBox.
|
int |
getMarginY()
Gets or sets a value specifying the margin height for a LegendBox.
|
java.util.EnumSet<LegendBoxStyles> |
getStyle()
Gets or sets the style of the legend box.
|
java.awt.Color |
getTextColor()
Gets or sets the color used for the text in the legend box.
|
java.util.List<TitleDockable> |
getTitles()
Returns a title object for the legend box.
|
boolean |
isPlotAreaOnly()
Allows the legend box margins to go outside of the chart's drawing area.
|
void |
resetContentLayout()
Set the property ContentLayout to its default value.
|
void |
resetFont()
Set the property Font to its default value.
|
void |
resetLineSpacing()
Set the property LineSpacing to its default value.
|
void |
resetMarginX()
Set the property MarginX to its default value.
|
void |
resetMarginY()
Set the property MarginY to its default value.
|
void |
resetPlotAreaOnly()
Set the property PlotAreaOnly to its default value.
|
void |
resetStyle()
Set the property Style to its default value.
|
void |
resetTextColor()
Set the property TextColor to its default value.
|
void |
setContentLayout(ContentLayout value)
Allows you to align the content for the legend box.
|
void |
setFont(java.awt.Font value)
Gets or sets the font of the Legend Box.
|
void |
setLineSpacing(double value)
Gets or sets the space in pixels between the LegendBox items
|
void |
setMarginX(int value)
Gets or sets a value specifying the margin width for a LegendBox.
|
void |
setMarginY(int value)
Gets or sets a value specifying the margin height for a LegendBox.
|
void |
setPlotAreaOnly(boolean value)
Allows the legend box margins to go outside of the chart's drawing area.
|
void |
setStyle(java.util.EnumSet<LegendBoxStyles> value)
Gets or sets the style of the legend box.
|
void |
setTextColor(java.awt.Color value)
Gets or sets the color used for the text in the legend box.
|
void |
sizeToFit()
Calculates and sets the best-fit size for the legend box.
|
addVisibleChangedListener, getBackColor, getBorder, getDock, getHeight, getWidth, getZOrder, isAutoSize, isVisible, removeVisibleChangedListener, resetAutoSize, resetBackColor, resetBorder, resetDock, resetHeight, resetVisible, resetWidth, resetZOrder, setAutoSize, setBackColor, setBorder, setDock, setHeight, setVisible, setWidth, setZOrderpublic ContentLayout getContentLayout()
Allows you to align the content for the legend box.
chart1.getLegendBox().setContentLayout(ContentLayout.NEAR);
PopulateSouthAmericaPopulation(chart1);
chart1.setGallery(Gallery.BAR);
chart1.getTitles().add(new TitleDockable("South American Countries Population"));
chart1.getAxisY().setScaleUnit(1000000);
chart1.getAxisY().getTitle().setText("(in Millions)");
public static void PopulateSouthAmericaPopulation(Chart chart1) {
SouthAmericaPopulation[] data = new SouthAmericaPopulation[]{
new SouthAmericaPopulation("Brazil", 201033000),
new SouthAmericaPopulation("Colombia", 47130000),
new SouthAmericaPopulation("Argentina", 41350000),
new SouthAmericaPopulation("Peru", 30476000),
new SouthAmericaPopulation("Venezuela", 29760000),
new SouthAmericaPopulation("Chile", 16841000),
new SouthAmericaPopulation("Ecuador", 15779000),
new SouthAmericaPopulation("Bolivia", 10517000)
};
ObjectProvider objProvider = new ObjectProvider(data);
chart1.getDataSourceSettings().setDataSource(objProvider);
}
public static class SouthAmericaPopulation {
public SouthAmericaPopulation(String country, double population) {
this.setCountry(country);
this.setPopulation(population);
}
private String privateCountry;
public final String getCountry() {
return privateCountry;
}
public final void setCountry(String value) {
privateCountry = value;
}
private double privatePopulation;
public final double getPopulation() {
return privatePopulation;
}
public final void setPopulation(double value) {
privatePopulation = value;
}
}
public static class Countries {
public Countries(String country, double lei, double gdppc, java.awt.Image flag) {
this.setCountry(country);
this.setLEI(lei);
this.setGDPPC(gdppc);
this.setFlag(flag);
}
private String privateCountry;
public final String getCountry() {
return privateCountry;
}
public final void setCountry(String value) {
privateCountry = value;
}
private double privateLEI;
public final double getLEI() {
return privateLEI;
}
public final void setLEI(double value) {
privateLEI = value;
}
private double privateGDPPC;
public final double getGDPPC() {
return privateGDPPC;
}
public final void setGDPPC(double value) {
privateGDPPC = value;
}
private java.awt.Image privateFlag;
public final java.awt.Image getFlag() {
return privateFlag;
}
public final void setFlag(java.awt.Image value) {
privateFlag = value;
}
}
resetContentLayoutpublic void setContentLayout(ContentLayout value)
Allows you to align the content for the legend box.
chart1.getLegendBox().setContentLayout(ContentLayout.NEAR);
PopulateSouthAmericaPopulation(chart1);
chart1.setGallery(Gallery.BAR);
chart1.getTitles().add(new TitleDockable("South American Countries Population"));
chart1.getAxisY().setScaleUnit(1000000);
chart1.getAxisY().getTitle().setText("(in Millions)");
public static void PopulateSouthAmericaPopulation(Chart chart1) {
SouthAmericaPopulation[] data = new SouthAmericaPopulation[]{
new SouthAmericaPopulation("Brazil", 201033000),
new SouthAmericaPopulation("Colombia", 47130000),
new SouthAmericaPopulation("Argentina", 41350000),
new SouthAmericaPopulation("Peru", 30476000),
new SouthAmericaPopulation("Venezuela", 29760000),
new SouthAmericaPopulation("Chile", 16841000),
new SouthAmericaPopulation("Ecuador", 15779000),
new SouthAmericaPopulation("Bolivia", 10517000)
};
ObjectProvider objProvider = new ObjectProvider(data);
chart1.getDataSourceSettings().setDataSource(objProvider);
}
public static class SouthAmericaPopulation {
public SouthAmericaPopulation(String country, double population) {
this.setCountry(country);
this.setPopulation(population);
}
private String privateCountry;
public final String getCountry() {
return privateCountry;
}
public final void setCountry(String value) {
privateCountry = value;
}
private double privatePopulation;
public final double getPopulation() {
return privatePopulation;
}
public final void setPopulation(double value) {
privatePopulation = value;
}
}
public static class Countries {
public Countries(String country, double lei, double gdppc, java.awt.Image flag) {
this.setCountry(country);
this.setLEI(lei);
this.setGDPPC(gdppc);
this.setFlag(flag);
}
private String privateCountry;
public final String getCountry() {
return privateCountry;
}
public final void setCountry(String value) {
privateCountry = value;
}
private double privateLEI;
public final double getLEI() {
return privateLEI;
}
public final void setLEI(double value) {
privateLEI = value;
}
private double privateGDPPC;
public final double getGDPPC() {
return privateGDPPC;
}
public final void setGDPPC(double value) {
privateGDPPC = value;
}
private java.awt.Image privateFlag;
public final java.awt.Image getFlag() {
return privateFlag;
}
public final void setFlag(java.awt.Image value) {
privateFlag = value;
}
}
value - resetContentLayoutpublic java.util.List<CustomLegendItem> getCustomItems()

CustomLegendItem c;
c = new CustomLegendItem();
c.setText("Custom Item");
c.setMarkerShape(MarkerShape.MARBLE);
c.setColor(new java.awt.Color(255,165,0,255));
chart1.getLegendBox().getCustomItems().add(c);
public java.awt.Font getFont()
Gets or sets the font of the Legend Box.
You can set the font for the entire chart using the setChartFont method.
When setting a font in Chart FX, you must create a new font object with the desired attributes and assign that object to the desired chart element every time you want to change the font.
Fonts can be specified by using the standard string notation for fully or partially qualifying a font object. For example, "Verdana,12,style=italic,Bold" produces a font of type Verdana, point size of 12 and font style of Italic and Bold.
For more information regarding the Font type, please refer to the Documentation.
To change the font for the series legend box text:
chart1.getLegendBox().setFont(new java.awt.Font("Arial",java.awt.Font.PLAIN, 12));
resetFontpublic void setFont(java.awt.Font value)
Gets or sets the font of the Legend Box.
You can set the font for the entire chart using the setChartFont method.
When setting a font in Chart FX, you must create a new font object with the desired attributes and assign that object to the desired chart element every time you want to change the font.
Fonts can be specified by using the standard string notation for fully or partially qualifying a font object. For example, "Verdana,12,style=italic,Bold" produces a font of type Verdana, point size of 12 and font style of Italic and Bold.
For more information regarding the Font type, please refer to the Documentation.
To change the font for the series legend box text:
chart1.getLegendBox().setFont(new java.awt.Font("Arial",java.awt.Font.PLAIN, 12));
value - resetFontpublic HighlightLegendAttributes getHighlight()
chart1.getLegendBox().getHighlight().setEnabled(true);
public LegendItemAttributesCollection getItemAttributes()
LegendItemAttributes lia; lia = new LegendItemAttributes(); chart1.getLegendBox().getItemAttributes().set(chart1.getSeries(), 1, lia); lia.setFontStyle(FontStyle.BOLD);
public double getLineSpacing()
chart1.getLegendBox().setLineSpacing(3);
resetLineSpacingpublic void setLineSpacing(double value)
chart1.getLegendBox().setLineSpacing(3);
value - resetLineSpacingpublic int getMarginX()
Gets or sets a value specifying the margin width for a LegendBox.
The setMarginY method may be used to control the margin height for a LegendBox.
The setLegendBox method of the Chart class is used to return the chart's LegendBox object.
To configure the X Margin for a legendbox to 50:
chart1.getLegendBox().setMarginX(50);
resetMarginXpublic void setMarginX(int value)
Gets or sets a value specifying the margin width for a LegendBox.
The setMarginY method may be used to control the margin height for a LegendBox.
The setLegendBox method of the Chart class is used to return the chart's LegendBox object.
To configure the X Margin for a legendbox to 50:
chart1.getLegendBox().setMarginX(50);
value - resetMarginXpublic int getMarginY()
Gets or sets a value specifying the margin height for a LegendBox.
The setMarginX method may be used to control the margin width for a LegendBox.
The setLegendBox method of the Chart class is used to return the chart's LegendBox object.
To configure the Y Margin for a legendbox to 50:
chart1.getLegendBox().setMarginY(50);
resetMarginYpublic void setMarginY(int value)
Gets or sets a value specifying the margin height for a LegendBox.
The setMarginX method may be used to control the margin width for a LegendBox.
The setLegendBox method of the Chart class is used to return the chart's LegendBox object.
To configure the Y Margin for a legendbox to 50:
chart1.getLegendBox().setMarginY(50);
value - resetMarginYpublic boolean isPlotAreaOnly()
Allows the legend box margins to go outside of the chart's drawing area.
If there is enough space and the legend is centered (default), there will be no noticeable difference when this method is configured. The difference is visible when there are many legend values, the drawing area is too small, the opposite gaps (e.g. top and bottom) are different or the legend is not centered.
By default the legends are drawn inside the chart drawing area, for example when the legend box is at the right, the first legend will be at the top of the chart area, it will not use the margin on top. If you set PlotAreaOnly to false, the margins will also be available for the legend.
To set the isPlotAreaOnly method to false:
chart1.getLegendBox().setPlotAreaOnly(false);
resetPlotAreaOnlypublic void setPlotAreaOnly(boolean value)
Allows the legend box margins to go outside of the chart's drawing area.
If there is enough space and the legend is centered (default), there will be no noticeable difference when this method is configured. The difference is visible when there are many legend values, the drawing area is too small, the opposite gaps (e.g. top and bottom) are different or the legend is not centered.
By default the legends are drawn inside the chart drawing area, for example when the legend box is at the right, the first legend will be at the top of the chart area, it will not use the margin on top. If you set PlotAreaOnly to false, the margins will also be available for the legend.
To set the isPlotAreaOnly method to false:
chart1.getLegendBox().setPlotAreaOnly(false);
value - resetPlotAreaOnlypublic java.util.EnumSet<LegendBoxStyles> getStyle()
Gets or sets the style of the legend box.
This method uses bitwise operators to turn on and off settings. To combine two flags. use the 'Or' bitwise operator.
This method uses bitwise operators to turn on and off settings. To combine two flags. use the 'Or' bitwise operator.
Configures the legend box to enables the context menu:
java.util.EnumSet<LegendBoxStyles> style = chart1.getLegendBox().getStyle(); style.add(LegendBoxStyles.SHOW_MENU); chart1.getLegendBox().setStyle(style);
resetStylepublic void setStyle(java.util.EnumSet<LegendBoxStyles> value)
Gets or sets the style of the legend box.
This method uses bitwise operators to turn on and off settings. To combine two flags. use the 'Or' bitwise operator.
This method uses bitwise operators to turn on and off settings. To combine two flags. use the 'Or' bitwise operator.
Configures the legend box to enables the context menu:
java.util.EnumSet<LegendBoxStyles> style = chart1.getLegendBox().getStyle(); style.add(LegendBoxStyles.SHOW_MENU); chart1.getLegendBox().setStyle(style);
value - resetStylepublic java.awt.Color getTextColor()
Gets or sets the color used for the text in the legend box.
Before you can see the text color assignments, the selected legend box must be visible.
You can assign the text for the values legend box using the setLabels or setText methods.
Named color are supported (e.g. Red), to use Hex notation you have to use quotes (e.g. "#FF00FF").
For more information regarding the Color type, please refer to the Documentation.
To set the legend box text to red:
chart1.getLegendBox().setTextColor(new java.awt.Color(255,0,0,255));
resetTextColorpublic void setTextColor(java.awt.Color value)
Gets or sets the color used for the text in the legend box.
Before you can see the text color assignments, the selected legend box must be visible.
You can assign the text for the values legend box using the setLabels or setText methods.
Named color are supported (e.g. Red), to use Hex notation you have to use quotes (e.g. "#FF00FF").
For more information regarding the Color type, please refer to the Documentation.
To set the legend box text to red:
chart1.getLegendBox().setTextColor(new java.awt.Color(255,0,0,255));
value - resetTextColorpublic java.util.List<TitleDockable> getTitles()
TitleDockable newTitle;
newTitle = new TitleDockable();
chart1.getLegendBox().getTitles().add(newTitle);
newTitle.setText("My Title");
newTitle.setChartFont(new java.awt.Font(newTitle.getFont(), FontStyle.BOLD));
newTitle.setDock(DockArea.TOP);
public void resetContentLayout()
setContentLayoutpublic void resetFont()
setFontpublic void resetLineSpacing()
setLineSpacingpublic void resetMarginX()
setMarginXpublic void resetMarginY()
setMarginYpublic void resetPlotAreaOnly()
isPlotAreaOnlypublic void resetStyle()
setStylepublic void resetTextColor()
setTextColorpublic void sizeToFit()
This method is particularly useful when the isAutoSize method is set to False, as it will allow you to recalculate the best-fit size of the legend box.
Instructs Chart FX to calculate the best-fit for the legend box:
chart1.getLegendBox().sizeToFit();
2014 Software FX, Inc. All Rights Reserved. Chart FX is a registered trademark of Software FX, Inc
All other names are trademarks or registered trademarks of their respective owners.