.exporting
class: Exporting
- class Exporting(**kwargs)[source]
Options to configure the export functionality enabled for the chart.
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', for_export: bool = False)
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:
filename (Path-like) – The name of a file to which the JSON string should be persisted. Defaults to
None
encoding (
str
) – The character encoding to apply to the resulting object. Defaults to'utf-8'
.for_export (
bool
) – IfTrue
, indicates that the method is being run to produce a JSON for consumption by the export server. Defaults toFalse
.
- 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, for_export: bool = False) 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
.for_export (
bool
) – IfTrue
, indicates that the method is being run to produce a JSON for consumption by the export server. Defaults toFalse
.
- Returns:
Trimmed
dict
- Return type:
- static trim_iterable(untrimmed, to_json=False, context: str = None, for_export: bool = False)
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
.for_export (
bool
) – IfTrue
, indicates that the method is being run to produce a JSON for consumption by the export server. Defaults toFalse
.
- Return type:
iterable
- property accessibility: ExportingAccessibilityOptions | None
Accessibility options for the exporting menu.
- Return type:
- property allow_html: bool | None
If
True
, allows HTML inside the chart (added using.use_html
properties present on various chart components) to be added directly to the exported image. This allows you to preserve complicated HTML structures like tables or bi-directional text in exported charts.Defaults to
False
.Warning
This setting is EXPERIMENTAL.
The HTML is rendered in a
foreignObject
tag in the generated SVG. The official export server is based on PhantomJS, which supports this, but other SVG clients, like Batik, do not support it. This also applies to downloaded SVG that you want to open in a desktop client.
- property buttons: ExportingButtons | None
Options for the export related buttons: print and export.
Note
In addition to the default buttons listed above, custom buttons can be added.
Warning
The
.buttons
property accepts anExportingButtons
instance as its value. This object is a descendent of the specialJavaScriptDict
which by default initially contains a ``’context- Return type:
ExportingButtons
- property chart_options
Additional chart options to be merged into the chart before exporting to an image format. This does not apply to printing the chart via the export menu.
For example, a common use case is to add data labels to improve readability of the exported chart, or to add a printer-friendly color scheme to exported PDFs.
Warning
To avoid a circular import error, this property REQUIRES that you supply a value that is an
Options
instance (e.g.HighchartsOptions
,HighchartsStockOptions
,HighchartsMapsOptions
, etc.). Unlike other Highcharts for Python properties, it does not acceptdict
or JSON (str
) values.Please be sure to either supply it a valid
Options
instance, or the value ofNone
.- Return type:
Options
orNone
- Raises:
HighchartsInstanceNeededError – if attempting to set it to a value that is not a
Options
(or descendent) instance.
- property csv: ExportingCSV | None
Options for exporting data to CSV or Microsoft Excel, or displaying the data in a HTML table or a JavaScript structure.
This module adds data export options to the export menu and provides JavaScript functions like
Chart.getCSV()
,Chart.getTable()
,Chart.getDataRows()
, andChart.viewData()
.Warning
The XLS converter is limited and only creates a HTML string that is passed for download, which works but creates a warning before opening. The workaround for this is to use a third party XLSX converter.
- Returns:
Configuration for exporting data to CSV or Microsoft Excel.
- Return type:
ExportingCSV
orNone
- property enabled: bool | None
If
True
, displays the export context button and allows for exporting the chart. IfFalse
, the context button will be hidden but JavaScript export API methods will still be available.Defaults to
True
.
- property error: CallbackFunction | None
JavaScript function that is called if the offline-exporting module fails to export a chart on the client side, and
Exporting.fallback_to_export_server()
is disabled.If
None
, a JavaScript exception is thrown instead. The JavaScript function receives two parameters, the exporting options, and the error from the module.- Returns:
JavaScript function code
- Return type:
CallbackFunction
orNone
- property fallback_to_export_server: bool | None
If
True
, falls back to the export server if the offline-exporting module is unable to export the chart on the client side. Defaults toTrue
.This happens for certain browsers, and certain features (e.g.
Exporting.allow_html()
), depending on the image type exporting to.Hint
For very complex charts, it is possible that export can fail in browsers that don’t support Blob objects, due to data URL length limits. It is recommended to define the
Exporting.error()
handler if disabling fallback, in order to notify users in case export fails.
- property fetch_options: dict | None
Options for the fetch request used when sending the SVG to the export server. Defaults to
None
.See also
MDN: Fetch for more information
- property filename: str | None
The filename (without file type extension) to use for the exported chart. Defaults to
'{constants.DEFAULT_EXPORTING_FILENAME}'
.
- property form_attributes: dict | None
An object containing additional key value data for the POST form that sends the SVG to the export server.
For example, a
target
can be set to make sure the generated image is received in another frame, or a customenctype
orencoding
can be set.
- property lib_url: str | None
Path where Highcharts will look for export module dependencies to load on demand if they don’t already exist on window.
Should currently point to location of the CanVG library, jsPDF and svg2pdf.js, which are all required for client side export in certain browsers.
An object consisting of definitions for the menu items in the context menu.
Each key value pair has a key that is referenced in the
menu_items
setting, and a value, which is an object with the following properties:onclick
: The click handler for the menu itemtext
: The text for the menu itemtextKey
: If internationalization is required, the key to a language string
Note
Custom text for
"exitFullScreen"
can be set only inlanguage
options (it is not a separate button).Defaults to:
{ "viewFullscreen": {}, "printChart": {}, "separator": {}, "downloadPNG": {}, "downloadJPEG": {}, "downloadPDF": {}, "downloadSVG": {} }
- Returns:
Definitions for menu items in the Exporting context menu.
- Return type:
MenuObject
orNone
- property pdf_font: PDFFontOptions | None
Settings for a custom font for the exported PDF, when using the
offline-exporting
module.This is used for languages containing non-ASCII characters, like Chinese, Russian, Japanese etc.
As described in the jsPDF docs, the 14 standard fonts in PDF are limited to the ASCII-codepage. Therefore, in order to support other text in the exported PDF, one or more TTF font files have to be passed on to the exporting module.
- Returns:
Additionl font settings for use in exporting PDFs.
- Return type:
PDFFontOptions
orNone
- property print_max_width: int | float | Decimal | None
When printing the chart from the menu item in the burger menu, if the on-screen chart exceeds this width, it is resized. After printing or cancelled, it is restored.
By default, set to
780
which makes the chart fit into typical paper format.Note
This does not affect the chart when printing the web page as a whole.
- Return type:
numeric or
None
- property scale: int | float | Decimal | None
Defines the scale or zoom factor for the exported image compared to the on-screen display. Defaults to
2
.While for instance a 600px wide chart may look good on a website, it will look bad in print. The default scale of
2
makes this chart export to a 1200px PNG or JPG.- Return type:
numeric or
None
- property show_export_in_progress: bool | None
If
True
, displays a message when export is in progress. Defaults toTrue
.Note
The message displayed can be adjusted in
Language.export_in_progress
.
- property show_table: bool | None
If
True
, shows an HTML table below the chart with the chart’s current data. Defaults toFalse
.
- property source_height: int | float | Decimal | None
The height of the original chart when exported, unless an explicit (JavaScript)
chart.height
is set, or a pixel width is set on the container.The height exported raster image is then multiplied by
Exporting.scale()
.- Return type:
numeric or
None
- property source_width: int | float | Decimal | None
The width of the original chart when exported, unless an explicit (JavaScript)
chart.width
is set, or a pixel width is set on the container.The width exported raster image is then multiplied by
Exporting.scale()
.- Return type:
numeric or
None
Caption for the data table. If not specified (
None
)`), will default to the chart title.Also accepts a
bool
value ofFalse
, which disables the table caption entirely.
- property type: str | None
Default MIME type for exporting if the JavaScript
chart.exportChart()
is called without specifying atype
option.Accepts:
'image/png'
'image/jpeg'
'application/pdf'
'image/svg+xml'
Defaults to
'image/png'
.
- property url: str | None
The URL for the server module converting the SVG string to an image format. By default this points to Highchart’s free web service:
'{constants.DEFAULT_EXPORTING_URL}'
.- Return type:
- Raises:
ValueError – if not a well-formed URL or path
- property use_multi_level_headers: bool | None
If
True
, uses multi-level (nested) headers in the exported data table. Defaults toTrue
.Warning
If
Exporting.csv.column_header_formatter
is specified, then the formatter must return objects for multi-level headers to work properly.
- property use_rowspan_headers: bool | None
If
True
and using multi-level headers, uses rowspans in the data table for headers that only have one level. Defaults toTrue
.
- property width: int | float | Decimal | None
An explicitly set pixel width for charts exported to PNG or JPG. Defaults to
None
.Note
If not specified (
None
), the default pixel width is a function of theChart.width()
orExporting.source_width()
andExporting.scale()
.- Return type:
numeric or
None
class: ExportingAccessibilityOptions
- class ExportingAccessibilityOptions(**kwargs)[source]
Accessibility options for the exporting menu.
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', for_export: bool = False)
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:
filename (Path-like) – The name of a file to which the JSON string should be persisted. Defaults to
None
encoding (
str
) – The character encoding to apply to the resulting object. Defaults to'utf-8'
.for_export (
bool
) – IfTrue
, indicates that the method is being run to produce a JSON for consumption by the export server. Defaults toFalse
.
- 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, for_export: bool = False) 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
.for_export (
bool
) – IfTrue
, indicates that the method is being run to produce a JSON for consumption by the export server. Defaults toFalse
.
- Returns:
Trimmed
dict
- Return type:
- static trim_iterable(untrimmed, to_json=False, context: str = None, for_export: bool = False)
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
.for_export (
bool
) – IfTrue
, indicates that the method is being run to produce a JSON for consumption by the export server. Defaults toFalse
.
- Return type:
iterable
Sub-components
Module |
Classes / Functions |
---|---|