The requested page is not available for the requested platform. You are viewing the content for Default platform.


  • 3 min to read

Legend is a chart element that displays series and series points' designations.

Legend example

Note that a legend's content depends on a series. In the case of a Cartesian series, a legend item's text is the series's display name (getDisplayName()/setDisplayName(String)). If the series is a Pie, a legend contains items for each pie point. The getLegendTextPattern()/setLegendTextPattern(String) methods configure the legend item's text.

How to: Change a legend's position and layout

You can place a legend all around the chart area; for example, at the top-center, either horizontally or vertically. The image below shows a legend placed at the top-center with a horizontal layout:

TopOutside-Centered horizontal legend

See this code to learn how to obtain the image:

Legend legend = new Legend();

Use the following symbols to configure a legend's layout and position.

Symbol Description
PieChart.getLegend() Returns the chart legend's options.
PieChart.setLegend(Legend) Specifies the chart legend's options.
Legend The legend of the chart.
Legend.getHorizontalPosition() Returns the horizontal position of the legend within the chart.
Legend.setHorizontalPosition(LegendHorizontalPosition) Specifies the horizontal position of the legend within the chart.
Legend.getVerticalPosition() Returns the vertical position of the legend within the chart.
Legend.setVerticalPosition(LegendVerticalPosition) Specifies the vertical position of the legend within the chart.
Legend.getOrientation() Returns the legend orientation.
Legend.setOrientation(LegendOrientation) Specifies the legend orientation.

How to: Show or hide a series in the legend

Use the setVisibleInLegend method, to show or hide an individual series in the legend:


How to: Configure a legend's appearance

You can style a legend like any other chart element using the following symbols:

Symbol Description
LegendStyle The storage of the chart legend's appearance settings.
Legend.getStyle() Returns the legend style.
Legend.setStyle(LegendStyle) Specifies the legend style.

Below are changeable appearance parameters:

Styleable legend elements

See the code snippet below to learn how to change this legend's style.

// All sizes are in pixels.
LegendStyle style = new LegendStyle();

TextStyle textStyle = new TextStyle();