.legend
class: Legend
- class Legend(**kwargs)[source]
The legend is a box containing a symbol and name for each series item or point item in the chart. Each series (or points in case of pie charts) is represented by a symbol and its name in the legend.
See also
It is possible to override the symbol creator function and create custom legend symbols.
Class Inheritance
- copy(other=None, overwrite=True, **kwargs)
Copy the configuration settings from this instance to the
other
instance.- Parameters:
other (
HighchartsMeta
) – The target instance to which the properties of this instance should be copied. IfNone
, will create a new instance and populate it with properties copied fromself
. Defaults toNone
.overwrite (
bool
) – ifTrue
, properties inother
that are already set will be overwritten by their counterparts inself
. Defaults toTrue
.kwargs – Additional keyword arguments. Some special descendents of
HighchartsMeta
may have special implementations of this method which rely on additional keyword arguments.
- Returns:
A mutated version of
other
with new property values
- classmethod from_dict(as_dict: dict, allow_snake_case: bool = True)
Construct an instance of the class from a
dict
object.
- classmethod from_js_literal(as_str_or_file, allow_snake_case: bool = True, _break_loop_on_failure: bool = False)
Return a Python object representation of a Highcharts JavaScript object literal.
- Parameters:
as_str_or_file (
str
) – The JavaScript object literal, represented either as astr
or as a filename which contains the JS object literal.allow_snake_case (
bool
) – IfTrue
, interpretssnake_case
keys as equivalent tocamelCase
keys. Defaults toTrue
._break_loop_on_failure (
bool
) – IfTrue
, will break any looping operations in the event of a failure. Otherwise, will attempt to repair the failure. Defaults toFalse
.
- Returns:
A Python object representation of the Highcharts JavaScript object literal.
- Return type:
HighchartsMeta
- classmethod from_json(as_json_or_file, allow_snake_case: bool = True)
Construct an instance of the class from a JSON string.
- Parameters:
as_json_or_file – The JSON string for the object or the filename of a file that contains the JSON string.
allow_snake_case (
bool
) – IfTrue
, interpretssnake_case
keys as equivalent tocamelCase
keys. Defaults toTrue
.
- Returns:
A Python objcet representation of
as_json
.- Return type:
HighchartsMeta
- get_required_modules(include_extension=False) List[str]
Return the list of URLs from which the Highcharts JavaScript modules needed to render the chart can be retrieved.
- to_dict() dict
Generate a
dict
representation of the object compatible with the Highcharts JavaScript library.Note
The
dict
representation has a property structure and naming convention that is intentionally consistent with the Highcharts JavaScript library. This is not Pythonic, but it makes managing the interplay between the two languages much, much simpler.
- to_js_literal(filename=None, encoding='utf-8', careful_validation=False) str | None
Return the object represented as a
str
containing the JavaScript object literal.- Parameters:
along the way using the esprima-python library. Defaults to
False
.Warning
Setting this value to
True
will significantly degrade serialization performance, though it may prove useful for debugging purposes.
- to_json(filename=None, encoding='utf-8')
Generate a JSON string/byte string representation of the object compatible with the Highcharts JavaScript library.
Note
This method will either return a standard
str
or abytes
object depending on the JSON serialization library you are using. For example, if your environment has orjson, the result will be abytes
representation of the string.- Parameters:
- Returns:
A JSON representation of the object compatible with the Highcharts library.
- Return type:
- static trim_dict(untrimmed: dict, to_json: bool = False, context: str = None) dict
Remove keys from
untrimmed
whose values areNone
and convert values that have.to_dict()
methods.- Parameters:
untrimmed (
dict
) – Thedict
whose values may still beNone
or Python objects.to_json (
bool
) – IfTrue
, will remove all keys fromuntrimmed
that are not serializable to JSON. Defaults toFalse
.context (
str
orNone
) – If provided, will inform the method of the context in which it is being run which may inform special handling cases (e.g. where empty strings may be important / allowable). Defaults toNone
.
- Returns:
Trimmed
dict
- Return type:
- static trim_iterable(untrimmed, to_json=False, context: str = None)
Convert any
EnforcedNullType
values inuntrimmed
to'null'
.- Parameters:
untrimmed (iterable) – The iterable whose members may still be
None
or Python objects.to_json (
bool
) – IfTrue
, will remove all members fromuntrimmed
that are not serializable to JSON. Defaults toFalse
.context (
str
orNone
) – If provided, will inform the method of the context in which it is being run which may inform special handling cases (e.g. where empty strings may be important / allowable). Defaults toNone
.
- Return type:
iterable
- property accessibility: LegendAccessibilityOptions | None
Accessibility options for the legend.
Note
Requires the Accessibility module.
- Return type:
LegendAccessibilityOptions
orNone
- property align: str | None
The horizontal alignment of the legend box within the chart area. Defaults to
'center'
.Valid values are:
'left'
'center'
'right'
In the case that the legend is aligned in a corner position, the
Legend.layout()
setting will determine whether to place it above/below or on the side of the plot area.
- property align_columns: bool | None
If the layout is horizontal and the legend items span over two lines or more, if the value is
True
will align the items into vertical columns.Setting this to
False
makes room for more items, but will look more messy.Defaults to
True
.
- property background_color: str | Gradient | Pattern | None
The background color or gradient for the legend. Defaults to
None
.
- property border_color: str | Gradient | Pattern | None
The border color drawn around the legend. Defaults to
'#999999'
.
- property border_radius: int | float | Decimal | None
The border radius (in pixels) applied to the legend border. Defaults to
0
.- Returns:
The border radius to apply to the legend border.
- Return type:
numeric or
None
- property border_width: int | float | Decimal | None
The border width (in pixels) applied to the legend border. Defaults to
0
.- Returns:
The border width to apply to the legend border.
- Return type:
numeric or
None
- property bubble_legend: BubbleLegend | None
The bubble legend is an additional element in legend which presents the scale of the bubble series.
Individual bubble ranges can be defined by user or calculated from series. In the case of automatically calculated ranges, a 1px margin of error is permitted.
- Return type:
BubbleLegend
orNone
- property enabled: bool | None
If
True
, displays the legend. IfFalse
, hides the legend. Defaults toFalse
.Note
There is also a series-specific option,
PlotOptions.series.show_in_legend()
, that can hide the series from the legend. In some series types this isFalse
by default, so it must set toTrue
in order to show the legend for the series.
- property floating: bool | None
If
True
, the plot area ignores the legend and can be rendered below the legend. IfFalse
, the legend is rendered visually distinct (not overlapping) the plot area. Defaults toFalse
.
- property item_checkbox_style: str | dict | None
Default styling for the checkbox next to a legend item when
Legend.show_checkbox()
isTrue
. Defaults to:'{"width": "13px", "height": "13px", "position":"absolute"}'
.
- property item_distance: int | float | Decimal | None
In a legend with horizontal layout, the itemDistance defines the pixel distance between each item. Defaults to
20
.- Return type:
numeric or
None
Default styling for the legend item when the corresponding series or data point is hidden. Defaults to:
'{"color": "#cccccc"}'
.Warning
Only a subset of CSS is supported, notably those options related to text.
Note
Properties are inherited from
Legend.style()
unless overridden here.
- property item_hover_style: str | dict | None
Default styling for the legend item when the corresponding series or data point is in a hover state. Defaults to:
'{"color": "#000000"}'
.Warning
Only a subset of CSS is supported, notably those options related to text.
Note
Properties are inherited from
Legend.style()
unless overridden here.
- property item_margin_bottom: int | float | Decimal | None
The bottom margin expressed in pixels for each legend item. Defaults to
0
.- Return type:
numeric or
None
- property item_margin_top: int | float | Decimal | None
The top margin expressed in pixels for each legend item. Defaults to
0
.- Return type:
numeric or
None
- property item_style: str | dict | None
Default styling for each legend item. Defaults to:
{"color": "#333333", "cursor": "pointer", "fontSize": "12px", "fontWeight": "bold", "textOverflow": "ellipsis"}
.Warning
Only a subset of CSS is supported, notably those options related to text. However, a
"width"
property can be added to control the text width.Note
The default
"textOverflow"
property makes long texts truncate. Set it toundefined
to wrap text instead.
- property item_width: int | float | Decimal | None
The width for each legend item, expressed in pixels. Defaults to
None
.By default, the items are laid out successively. In a horizontal layout, if the items are laid out across two rows or more, they will be vertically aligned depending on the
Legend.align_columns()
setting.- Return type:
numeric or
None
- property label_format: str | None
A format string for each legend label. Defaults to:
'{name}'
.Note
Available variables relate to properties on the
{{series}}
, or the{{point}}
in the case of pie charts.
- property label_formatter: CallbackFunction | None
A JavaScript callback function that formats each of the series’ labels.
Note
The (JavaScript)
this
keyword refers to the series object for most chart types, and refers to the point object for pie charts.- Return type:
CallbackFunction
orNone
- property layout: str | None
The layout of the legend items. Defaults to
'horizontal'
.Accepts:
'horizontal'
'vertical'
'proximate'
When proximate, the legend items will be placed as close as possible to the graphs they’re representing, except in inverted charts or when the legend position does not allow it.
- property margin: int | float | Decimal | None
If the plot area sized is calculated automatically and the legend is not floating, the legend margin is the space between the legend and the axis labels or plot area. Defaults to
12
.- Return type:
numeric or
None
- property max_height: int | float | Decimal | None
The maximum height for the legend, expressed in pixels. Defaults to
None
.When the maximum height is extended, navigation will show.
- Return type:
numeric or
None
Options for paging or navigation within the legend when the legend overflows the available space.
Hint
Navigation works well on screen, but not in static exported images. One way of working around that is to increase the chart height in export.
- Return type:
LegendNavigation
orNone
- property padding: int | float | Decimal | None
The inner padding of the legend box. Defaults to
8
.- Return type:
numeric or
None
- property reversed: bool | None
If
True
, reverses the order of the legend items compared to the order of series/points as defined in the configuration object. Defaults toFalse
.
- property rtl: bool | None
If
True
, displays the symbol on the right side of the text rather than the left (this is common in RTL languages like Arabic or Hebrew). Defaults toFalse
.
- property shadow: bool | ShadowOptions | None
Configuration of a drop shadow applied to the legend box. Accepts either a boolean value of
False
which disables any shadow, or aShadowOptions
instance with the applicable configuration.Defaults to
False
.Warning
Requires that
Legend.background_color()
be set.
- property square_symbol: bool | None
If
True
, the legend symbol width will be the same as the symbol height, which in turn defaults to the font size of the legend items. Defaults toTrue
.
- property symbol_height: int | float | Decimal | None
The height of the symbol (in pixels) for series types that use a rectangle in the legend. Defaults to the font size of legend items.
- Return type:
numeric or
None
- property symbol_padding: int | float | Decimal | None
The pixel padding between the legend item symbol and the item text. Defaults to
5
.- Return type:
numeric or
None
- property symbol_radius: int | float | Decimal | None
The border radius of symbol for series types that use a rectangle in the legend. Defaults to one half of the
Legend.symbol_height
.- Return type:
numeric or
None
- property symbol_width: int | float | Decimal | None
The width of the legend item symbol (in pixels). When
Legend.square_symbol()
isTrue
, this defaults to theLegend.symbol_height()
, otherwise16
.- Return type:
numeric or
None
- property title: LegendTitle | None
A title to be added on top of the legend.
- Return type:
LegendTitle
orNone
- property use_html: bool | None
If
True
, will use HTML to render the legend item texts. IfFalse
, will use SVG or WebGL as applicable.Defaults to
False
.
- property vertical_align: str | None
The vertical alignment of the legend box. Defaults to
'bottom'
.Accepts:
'bottom'
'middle'
'top'
Hint
Vertical position can be further determined by the
Legend.y()
option.Note
If the legend is aligned in a corner position, the
Legend.layout()
setting will determine whether to place it above/below or on the side of the plot area.When the layout option is
'proximate'
, thevertical_align
option does not apply.
- property width: int | float | Decimal | str | None
The width of the legend box. If expressed as a numeric value, the value is in pixels. If as a
str
, then accepts a value expressed as a percentage of the chart area (e.g.'40%'
).If
None
, then defaults to the full chart width if above or below the chart and half the chart width aligned to the left or right of the chart.Defaults to
None
.- Return type:
numeric or
None
- property x: int | None
The x position offset of the legend relative to its horizontal alignment (
Legend.align()
) withinChart.spacing_left()
andChart.spacing_right()
. Defaults to0
.Note
Negative values move it to the left, positive values move it to the right.
- Return type:
numeric or
None
- property y: int | None
The y position offset of the legend relative to its vertical alignment (
Legend.vertical_align()
) withinChart.spacing_top()
andChart.spacing_bottom()
. Defaults to0
.Note
Negative values move it up, positive values move it down.
- Return type:
numeric or
None
Sub-components
Module |
Classes / Functions |
---|---|