Making the Graph Legend Scrollable

By default in a BI Beans Java-client graph, the legend displays markers for each series that the graph displays. You can arrange for the legend to display only some of the legend markers at a time, allowing users to scroll through the legend to see all of the markers.

Note: In a thin graph, users cannot interact with the scrollbar, so you should not make the legend scrollable. By default, markers for all series appear in the legend, and the legend is not scrollable.

Automatic graph layout prevents the legend from being scrollable. If you want a scrollable legend in a Java-client application, then you must first disable the automatic layout in the graph.

The following three properties of the graph affect how many legend markers appear in the legend at a time, and whether a scrollbar appears.

Property

Description

LegendScrollbarPresence

Whether a scrollbar appears in the legend

LegendSeriesCount

The number of markers that appear in a legend at a time

LegendSeriesStart

The first series for which to display a marker in the legend

Example: Making the Legend Scrollable

The following example shows how to provide a scrollbar for the legend. This code assumes that you have a graph that is named myGraph.


// disable automatic graph layout myGraph.setAutoLayout(Graph.AL_NEVER); // display a scrollbar whenever there are more series // in the graph than in the legend // (you can find this by calling myGraph.getDisplaySeries) // this is actually the default, so you do not have to set it myGraph.setLegendScrollbarPresence(Graph.SP_AS_NEEDED); // for this example, we want only six legend markers to // appear at a time; you might use a variable int seriesInLegend = 6; // set the number of markers to appear in the legend myGraph.setLegendSeriesCount(seriesInLegend); // start with the first series // this is also the default myGraph.setLegendSeriesStart(0);

Note: In a thin graph, you should ensure that LegendSeriesCount is 0 to show markers for all series, and you should set LegendScrollbarPresence to SP_NEVER.


// setting properties to ensure that all markers appear in a thin graph myGraph.setLegendSeriesCount(0); myGraph.setLegendScrollbarPresence(Graph.SP_NEVER);

The Graph.doAutoLayout method sets these properties, so if you call that method for automatic layout, then you do not need to set the properties after that:


myGraph.setAutoLayout(Graph.AL_NEVER); myGraph.doAutoLayout(Graph.RESET_PROPERTIES); // doAutoLayout sets the LegendSeriesCount and // ScrollbarPresence properties