Legends

Topics:

The following properties and methods control graph legends.

Legend Properties

These properties are used to control how the legend area, legend markers, and legend text are imaged in a graph:

  • LegendDisplay (true/false); Enables/disables drawing of the legend box. True is the default value if there is more than one measure.
  • LegendMarkerPosition (0...4); Sets the location and format of the graph legends. 0 is the default value.
  • LegendMarkersPerRow(); Controls the number of markers per row shown in the legend area.
  • LegendOrient(0...2); Controls orientation of markers and labels in the legend area.
  • LegendReverse(true/false); Controls the order of legend markers and labels.
  • LegendSeriesStart(); This property defines the first series to appear in the legend area.
  • LegendTextAutofit (true/false); Enables (true)/disables (false) auto-fitting of the legend text. True is the default value.
  • UseSeriesShapes (true/false); Enables/disables the use of the shapes defined by the setMarkerShape() method. This property is ignored if the LegendMarkerPosition property sets the legend text to display on top of the legend marker.
    graph
  • SquareMarkers (true/false); Can be used to force markers in the legend area to fit in a perfectly square rectangle regardless of their shape. This property is ignored if the LegendMarkerPosition property sets the legend text to display on top of the legend marker.

Note: All scroll, zoom, and pan operations require that the graph be rendered as an applet in the browser.

Legend Methods

You can use these methods to control how the legend area, legend markers, and legend text are imaged in a graph:

  • setLegendOrient(int newValue); Sets the orientation of the legends in a graph.
  • get/setLegendRect(); Gets/sets the size and location of the legend rectangle. Also see Virtual Coordinate System for additional information about the virtual coordinate system.
  • setLegendTextAutofit(boolean newValue); Enables (true)/disables (false) auto-fitting of the legend text.

Setting the Legend Position

How to:

You can select the position of the legend on your graph using setLegendPosition.

The code has been written so that additional presets can be added later if desired (for example place the legend inside the chart in the upper right corner). These positions are independent of Place Default Elements (PDE).

Place Default Elements should fix positioning issues. Calling setLegendPosition(-1) tells the legend engine to leave the legend's position alone.

Syntax: How to Set the Legend Position

setLegendPosition (value);

where:

value

Is one of the following:

  • FREE FLOAT = -1;
  • AUTO = 0;
  • BOTTOM = 1;
  • RIGHT = 2;
  • LEFT = 3;
  • TOP = 4;
  • RIGHT TOP = 5;
  • RIGHT BOTTOM = 6;
  • LEFT TOP = 7;
  • LEFT BOTTOM = 8;
  • BOTTOM LEFT = 9;
  • BOTTOM RIGHT = 10;
  • TOP LEFT = 11;
  • TOP RIGHT = 12;

Example: Free Float Legend

restoreDefaults();
setDisplay(getFootnote(), false);
setDisplay(getY1MajorGrid(),false);
setDisplay(getO1MajorGrid(),false);
setGridStyle(getO1MinorGrid(),0);
setRect(getLegendArea(),new
Rectangle(-11318,5359,9066,5438));
setLegendPosition( -1);
setDisplay(getFootnote(), false);
setSubtitleString("setLegendPosition(-1)");
setTitleString("Free Float");
setPlace(true); 

The output is:

Free Float Legend

Example: Auto Legends

restoreDefaults();
setLegendPosition(0);
setDisplay(getFootnote(), false);
setSubtitleString("setLegendPosition(0)");
setTitleString("Auto");
setPlace(true);

The output is:

Auto Legend
restoreDefaults();
setLegendPosition(0);
setRect(getLegendArea(),new
Rectangle(8237,-1290,6637,11349));
setTitleString("Auto");
setSubtitleString("setLegendPosition(0)");
setFootnoteString("When the legend is taller
   than wide, 'auto' places on the right");
setPlace(true);

The output is:

Auto Legend

Example: Bottom Legend

restoreDefaults();
setLegendPosition(1);
setDisplay(getFootnote(), false);
setSubtitleString("setLegendPosition(1)");
setTitleString("Bottom");
setPlace(true);

The output is:

Bottom Legend

Example: Right Legend

restoreDefaults();
setLegendPosition(2);
setDisplay(getFootnote(), false);
setSubtitleString("setLegendPosition(2)");
setTitleString("Right");
setPlace(true);

The output is:

Right Legend

Example: Left Legend

restoreDefaults();
setLegendPosition(3);
setDisplay(getFootnote(), false);
setSubtitleString("setLegendPosition(3)");
setTitleString("Left");
setPlace(true);

The output is:

Left Legend

Example: Top Legend

restoreDefaults();
setLegendPosition(4);
setDisplay(getFootnote(), false);
setSubtitleString("setLegendPosition(4)");
setTitleString("Top");
setPlace(true);

The output is:

Top Legend

Example: Right Top Legend

restoreDefaults();
setLegendPosition(5);
setDisplay(getFootnote(), false);
setSubtitleString("setLegendPosition(5)");
setTitleString("Right Top");
setPlace(true);

The output is:

Right Top Legend

Example: Right Bottom Legend

restoreDefaults();
setLegendPosition(6);
setDisplay(getFootnote(), false);
setSubtitleString("setLegendPosition(6)");
setTitleString("Right Bottom");
setPlace(true);

The output is:

Right Bottom Legend

Example: Left Top Legend

restoreDefaults();
setLegendPosition(7);
setDisplay(getFootnote(), false);
setSubtitleString("setLegendPosition(7)");
setTitleString("Left Top");
setPlace(true);

The output is:

Left Top Legend

Example: Left Bottom Legend

restoreDefaults();
setLegendPosition(8);
setDisplay(getFootnote(), false);
setSubtitleString("setLegendPosition(8)");
setTitleString("Left Bottom");
setPlace(true);

The output is:

Left Bottom Legend

Example: Bottom Left Legend

restoreDefaults();
setLegendPosition(9);
setDisplay(getFootnote(), false);
setSubtitleString("setLegendPosition(9)");
setTitleString("Bottom Left");
setPlace(true);

The output is:

Bottom Left Legend

Example: Bottom Right Legend

restoreDefaults();
setLegendPosition(10);
setDisplay(getFootnote(), false);
setSubtitleString("setLegendPosition(10)");
setTitleString("Bottom Right");
setPlace(true);

The output is:

Bottom Right Legend

Example: Top Left Legend

restoreDefaults();
setLegendPosition(11);
setDisplay(getFootnote(), false);
setSubtitleString("setLegendPosition(11)");
setTitleString("Top Left");
setPlace(true);

The output is:

Top Left Legend

Example: Top Right Legend

restoreDefaults();
setLegendPosition(12);
setDisplay(getFootnote(), false);
setSubtitleString("setLegendPosition(12)");
setTitleString("Top Right");
setPlace(true);

The output is:

Top Right Legend

WebFOCUS

Feedback