Legend identifies the patterns or colors that are assigned to the data series or categories in a chart.
In Davisor Chart, legend can be rendered into the same image with some chart or as a separate image. A separate image gives more flexibility to the legend positioning for example in the web page, when the embedded one is a must in servlet use. An external legend is created by defining chartType="legend". An internal legend is created by giving a <legend> tag into chart attributes.
Legend appearance follows the chart appearance as faithfully as possible so it uses chart rendering attributes. However, some attributes can be set specifically for the legend by giving them inside the <legend> tag. These affect to both - internal and external - legend types, but some (like legendAlignment) are not meaningfull in external legend. These attributes include:
Background fill color, legend border color, and legend border style and thickness are controlled by backPaint, backColor, and backStroke respectively. These attributes default to generic paint, color, and stroke attributes. By default background fill color and border stroke are not defined, thus the legend entries are drawn straight onto chart background. Border color is by default black, so the border can be shown just by setting the stroke.
Each legend entry consists of a symbol and a name. The symbol attributes are taken from the chart attributes. However, the relative gap between symbols can be adjusted by legend attribute gap. It takes values from 0 to 100. The font and the color of the name can be adjusted by legend attributes labelFont and labelColor (defaulting to font and color respectively).
There are four supported values for alignment as shown in the images below.
![]() |
![]() |
| Up | Down |
![]() |
![]() |
| Right (the default) | Left |
Margins affect to legend position, too. Alignment has no effect to external legends.
There are a few legend types that can be selected. These types are:
If an external legend that is capable of showing visualization scales is wanted, the legend has to be created by defining it in chartType attribute. For example, for a paint scale legend the attribute and it's value would be chartType="paintLegend". The legendType attribute is ignored in external legends.
|
| Paint scale legend. |
By default there is a small (5 pixels) offset between legend and the chart, but no margins between legend and the image edges. All these margins can be adjusted by using the marginLeft, marginRight, marginTop, and marginBottom attributes, or by using the common margin attribute. The directions are based on the legend, thus for example the marginLeft attribute adjusts the margin on the left side of the legend.
The default orientation of the legend depends from the given alignment of the legend. The default orientation is horizontal for up and down alignments and vertical for left and right alignments. For an external legend, the default orientation is vertical.
With the orientation attribute the orientation can be set to a desired value. The effect of setting the orientation is shown below.
![]() |
| Vertical orientation |
|
| A custom legend. |