---
schema_version: "1"
id: 757e4731e30e5544b0da66bda54d2793d823a23e9bd9ebcf3ebc929d3c070eb7
title: apex:legend
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-pages-developers-guide/guides/pages/components/pages-compref-legend.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-compref-legend.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: c3db561a9fd0011e7bdee84a77d56a99782f372ef8af0f0385315bed46153011
products:
  - Visualforce Developer Guide
  - Platform Developer Content
---

# apex:legend

Defines a chart legend. This component offers additional configuration options beyond the defaults used by the legend attribute of the `<apex:chart>` component.

**Note:** This component must be enclosed within an `<apex:chart>` component.

## Example

```apex
<!-- Page: -->
<apex:chart height="400" width="700" data="{!data}">
    <apex:legend position="right"/>
    <apex:axis type="Numeric" position="left" fields="data1,data2"
        title="Opportunities Closed" grid="true"/>
    <apex:axis type="Category" position="bottom" fields="name"
        title="Month of the Year"/>
    <apex:lineSeries title="Closed-Won" axis="left" xField="name" yField="data1"/>
    <apex:lineSeries title="Closed-Lost" axis="left" xField="name" yField="data2"/>
</apex:chart>
```

## Attributes

|Attribute Name|Attribute Type|Description|Required?|API Version|Access|
|--------------|--------------|-----------|---------|-----------|------|
|`font`|String|The font to be used for the legend text, as a CSS-style font definition. If not specified, this value defaults to "12px Helvetica".| |23.0||
|`id`|String|An identifier that allows the chart component to be referenced by other components on the page.| |23.0|global|
|`padding`|Integer|The amount of spacing between the legend border and the contents of the legend, in pixels.| |23.0||
|`position`|String|The position of the legend, in relation to the chart. Valid options are: left, right, top, or bottom|Yes|23.0||
|`rendered`|Boolean|A Boolean value that specifies whether the chart legend is rendered with the chart. If not specified, this value defaults to true.| |23.0||
|`spacing`|Integer|The amount of spacing between legend items, in pixels.| |23.0||

**See Also**  


-   [apex:chart](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-compref-chart.md)
-   [Chart Layout and Annotation](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/charting/pages-charting-appearance-layout.md)

