Legend creates a key for a map and is useful for displaying titles, descriptions and keys for what is being mapped, horizontally or vertically. Based on TileMill CSS Legend.
Legend makes it easy to add a key to your UI, for example to a map or to a PrimeFaces Timeline. Title and footer are attributes or facets.
<div class="card">
<h5>Basic Usage</h5>
<p>Legend makes it easy to add a key to your UI, for example to a map or to a PrimeFaces Timeline. Title and footer are attributes or facets.</p>
<h:form id="formBasicUsage">
<p:panelGrid id="pnlLegend" columns="2" styleClass="p-noborder" layout="tabular">
<p:outputLabel value="Vertical"/>
<pe:legend layout="vertical" widgetVar="lgndVertical" values="#{legendController.values}" title="Vertical Title" footer="Source: PrimeFaces"/>
<p:spacer/>
<p:spacer/>
<p:outputLabel value="Horizontal"/>
<pe:legend layout="horizontal" widgetVar="lgndHorizontal" values="#{legendController.values}">
<f:facet name="title">
Horizontal Title Facet
</f:facet>
<f:facet name="footer">
Source: <a href="http://www.primefaces.org">PrimeFaces Rocks!</a>
</f:facet>
</pe:legend>
</p:panelGrid>
</h:form>
</div>
package org.primefaces.extensions.showcase.controller.legend;
import java.io.Serial;
import java.io.Serializable;
import java.util.LinkedHashMap;
import jakarta.annotation.PostConstruct;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
/**
* Legend Controller.
*
* @author Melloware [email protected]
*/
@Named
@ViewScoped
public class LegendController implements Serializable {
@Serial
private static final long serialVersionUID = 20120224L;
private LinkedHashMap<String, String> values;
@PostConstruct
public void init() {
values = new LinkedHashMap<String, String>();
values.put("0 - 20%", "#F1EEF6");
values.put("40%", "#BDC9E1");
values.put("60%", "#74A9CF");
values.put("80%", "#2B8CBE");
values.put("100%", "#045A8D");
}
public LinkedHashMap<String, String> getValues() {
return values;
}
public void setValues(final LinkedHashMap<String, String> values) {
this.values = values;
}
}