legend

Specifies the options of a chart's legend.

Type: Object

The dxChart widget can include a legend - an explanatory component that helps you identify a series. Each series is represented by an item on a Legend. An item marker identifies the series color. An item label displays the series title. To set the required position for a legend and its items, to customize the font settings for item labels, and to specify the size of item markers, use the properties of the legend configuration object. To learn more on the legend and its options, refer to the Legend topic.

Show Example:
jQuery

In this example, the legend's horizontalAlignment and verticalAlignment options are changed.


                                    

                                    

backgroundColor

Specifies a color for the legend's background.

Type: String
Default Value: undefined

Show Example:
jQuery

In this example, the legend's backgroundColor option is set to lightyellow.


                                    

                                    

border

Specifies legend border options.

Type: Object

Use this object to make a legend's border visible/invisible and set up such border options as color, width etc.

Show Example:
jQuery

This example shows how to customize the appearance of the legend border.


                                    

                                    

columnCount

Specifies how many columns it takes to arrange legend items.

Type: Number
Default Value: 0

To arrange legend items, specify how many rows and columns they must occupy. To do this, use the rowCount and columnCount properties.

Show Example:
jQuery

In this example, the legend items are displayed in 2 columns.


                                    

                                    

columnItemSpacing

Specifies a blank space between legend columns in pixels.

Type: Number
Default Value: 8

Show Example:
jQuery

In this example, the legend items are displayed in 2 columns with 4 pixel spacing.


                                    

                                    

customizeText

Specifies a callback function that returns the text to be displayed by legend items.

Type: function(seriesInfo)
Function parameters:
seriesInfo: Object
Information about the series to be presented in the legend.
Object structure:
seriesName: String
Specifies the name of the series for which the current legend item is created.
seriesIndex: Number
Specifies the index of the series for which the current legend item is created.
seriesColor: String
Specifies the color of the series for which the current legend item is created.
Return Value: String
The text to be displayed by a legend item.

By default, legend items identify series by color and name. You can also provide other information instead of the series name. To do this, implement a callback function for this property, and return the required text. Use the fields of the object passed as the function's parameter in the returned text. For instance, you can use the series name or index if it is more appropriate in your case.

Alternatively, you can use the this object within the function. This object has the same structure as the object passed as a parameter.

Show Example:
jQuery

In the example below, additional text is added to the legend item values using the customizeText option.


                                    

                                    

equalColumnWidth

Specifies whether or not item columns in the legend have an equal width.

Type: Boolean
Default Value: false
Accepted Values: true|false

When this property is set to false, the width of the item column is determined by the longest text. When this property is set to true, all item columns have an equal width.

Show Example:
jQuery

Use the check box below to switch between the values of the legend's equalColumnWidth option.


                                    

                                    

font

Specifies font options for the text displayed in the legend.

Type: Object

Show Example:
jQuery

In this example, the legend item text's font options are changed.


                                    

                                    

horizontalAlignment

Specifies a legend's position on the chart.

Type: String
Default Value: 'right'
Accepted Values: 'right' | 'center' | 'left'

Show Example:
jQuery

Use the drop-down list below to change the legend's horizontalAlignment option.


                                    

                                    

hoverMode

Specifies what series elements to highlight when a corresponding item in the legend is hovered over.

Type: String
Default Value: 'includePoints'
Accepted Values: 'includePoints' | 'excludePoints' | 'none'

In the dxChart widget, legend items represent series. When a legend item is hovered over, the corresponding series is highlighted. To prevent this behavior, set the hoverMode property to 'none'.

You can set a custom 'hover' style for a series and/or its points. To do this, use the series' hoverStyle configuration object and/or the point | hoverStyle configuration object.

Show Example:
jQuery

Change the value of the legend's hoverMode option using the drop-down list below, and hover over one of the legend items to see the effect.


                                    

                                    

itemTextPosition

Specifies the position of text relative to the item marker.

Type: String
Default Value: undefined
Accepted Values: 'right' | 'left' | 'top' | 'bottom'

A legend item consists of a marker that indicates the series (for the dxChart widget) / point (for the dxPieChart widget) color and text that specifies the name of the series/point. Use the itemTextPosition property to specify how the text should be positioned relative to the item marker.

Show Example:
jQuery

Use the drop-down list below to change the itemTextPosition option.


                                    

                                    

margin

Specifies the distance between the legend and surrounding widget elements or container borders in pixels.

Type: Number|Object
Default Value: 10

When this option is set to a number, the specified margin applies to all the sides of the legend. Alternatively, the margin option can be set to an object. This object specifies margins for each side of the legend separately.

Whether or not the specified margin is applied to a particular side of the legend depends on the legend's location. The location is determined by the horizontalAlignment and verticalAlignment options. Refer to the top, bottom, left and right options' description to discover when the margin applies to the corresponding side of the legend.

LegendMargin ChartJS

markerSize

Specifies the size of item markers in the legend in pixels.

Type: Number
Default Value: 20

Show Example:
jQuery

In this example, the size of the legend item markers is altered to 10.


                                    

                                    

orientation

Specifies whether to place legend items horizontally or vertically.

Type: String
Default Value: undefined
Accepted Values: 'vertical' | 'horizontal'

When this option is set to 'vertical', legend items are displayed vertically (i.e., in a column). When this option is set to 'horizontal', legend items are displayed horizontally (i.e, in a row). When this option is not defined, the legend orientation is chosen automatically.

Show Example:
jQuery

Use the drop-down list below to change the legend's orientation option.


                                    

                                    

paddingLeftRight

Specifies a blank space between a legend's left/right boundaries and the inner item boundaries in pixels.

Type: Number
Default Value: 10

LegendPadding ChartJS

paddingTopBottom

Specifies a blank space between a legend's top/bottom boundaries and the inner item boundaries in pixels.

Type: Number
Default Value: 10

LegendPadding ChartJS

position

Specifies whether the legend is located outside or inside the chart's plot.

Type: String
Default Value: 'outside'
Accepted Values: 'outside' | 'inside'

In addition to this option, use the legend's horizontalAlignment, verticalAlignment and orientation options to specify the legend layout.

Show Example:
jQuery

Use the drop-down list below to change the chart's legend position.


                                    

                                    

rowCount

Specifies how many rows it takes to arrange legend items.

Type: Number
Default Value: 0

To arrange legend items, specify how many rows and columns they must occupy. To do this, use the rowCount and columnCount properties.

Show Example:
jQuery

In this example, the legend items are displayed in 2 rows. In addition, the legend position on a chart is changed using the horizontalAlignment and veticalAlignment options, and the position of the legend item text is changed using the itemTextPosition option.


                                    

                                    

rowItemSpacing

Specifies a blank space between legend rows in pixels.

Type: Number
Default Value: 8

Show Example:
jQuery

In the example below, the legend items are displayed in 2 rows with 4 pixel spacing. In addition, the position of the legend is set using the horizontalAlignment and verticalAlignment options.


                                    

                                    

verticalAlignment

Specifies a legend's position on the chart.

Type: String
Default Value: 'top'
Accepted Values: 'top' | 'bottom'

Show Example:
jQuery

Use the drop-down list below to change the legend's verticalAlignment option.


                                    

                                    

visible

Specifies the visibility state of the chart's legend.

Type: Boolean
Default Value: true
Accepted Values: true|false

Show Example:
jQuery

Use the check box at the bottom to change legend visibility.