.chart
class: Chart
- class Chart(**kwargs)[source]
Python representation of a Highcharts
Chart
object.Class Inheritance
- add_series(*series)[source]
Adds
series
to theChart.options.series
property.- Parameters:
series (one or more
SeriesBase
or coercable) – One or more series instances (descended fromSeriesBase
) or an instance (e.g.dict
,str
, etc.) coercable to one
- copy(other=None, overwrite=True, **kwargs)[source]
Copy the configuration settings from this chart to the
other
chart.- Parameters:
other (
Chart
) – The target chart to which the properties of this chart should be copied. IfNone
, will create a new chart 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
.preserve_data (
bool
) – IfTrue
, will preserve the data values in any series contained inother
and the configuration of theoptions.data
property, but will still copy other properties as applicable. IfFalse
, will overwrite data inother
with data fromself
. 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
- display(global_options=None)[source]
Display the chart in Jupyter Labs or Jupyter Notebooks.
- Raises:
HighchartsDependencyError – if ipython is not available in the runtime environment
- download_chart(format='png', scale=1, width=None, filename=None, auth_user=None, auth_password=None, timeout=0.5, server_instance=None, **kwargs)[source]
Export a downloaded form of the chart using a Highcharts Export Server.
- Parameters:
filename (Path-like or
None
) – The name of the file where the exported chart should (optionally) be persisted. Defaults toNone
.auth_user (
str
orNone
) – The username to use to authenticate against the Export Server, using basic authentication. Defaults toNone
.auth_password (
str
orNone
) – The password to use to authenticate against the Export Server (using basic authentication). Defaults toNone
.timeout (numeric or
None
) – The number of seconds to wait before issuing a timeout error. The timeout check is passed if bytes have been received on the socket in less than thetimeout
value. Defaults to0.5
.server_instance (
ExportServer
orNone
) – Provide an already-configuredExportServer
instance to use to programmatically produce the exported chart. Defaults toNone
, which causes Highcharts for Python to instantiate a newExportServer
instance.
Note
All other keyword arguments are as per the
ExportServer
constructor.
- classmethod from_csv(as_string_or_file, property_column_map, series_type, has_header_row=True, series_kwargs=None, options_kwargs=None, chart_kwargs=None, delimiter=',', null_text='None', wrapper_character="'", line_terminator='\r\n', wrap_all_strings=False, double_wrapper_character_when_nested=False, escape_character='\\', is_maps_chart=False)[source]
Create a new
Chart
instance with data populated from a CSV string or file.Note
For an example
LineSeries
, the minimum code required would be:my_chart = Chart.from_csv('some-csv-file.csv', property_column_map = { 'x': 0, 'y': 3, 'id': 'id' }, series_type = 'line')
As the example above shows, data is loaded into the
my_chart
instance from the CSV file with a filenamesome-csv-file.csv
. Thex
values for each data point will be taken from the first (index 0) column in the CSV file. They
values will be taken from the fourth (index 3) column in the CSV file. And theid
values will be taken from a column whose header row is labeled'id'
(regardless of its index).- Parameters:
as_string_or_file (
str
or Path-like) –The CSV data to use to pouplate data. Accepts either the raw CSV data as a
str
or a path to a file in the runtime environment that contains the CSV data.Tip
Unwrapped empty column values are automatically interpreted as null (
None
).property_column_map (
dict
) –A
dict
used to indicate which data point property should be set to which CSV column. The keys in thedict
should correspond to properties in the data point class, while the value can either be a numerical index (starting with 0) or astr
indicating the label for the CSV column.series_type (
str
) – Indicates the series type that should be created from the CSV data.has_header_row (
bool
) – IfTrue
, indicates that the first row ofas_string_or_file
contains column labels, rather than actual data. Defaults toTrue
.series_kwargs (
dict
orNone
) –An optional
dict
containing keyword arguments that should be used when instantiating the series instance. Defaults toNone
.Warning
If
series_kwargs
contains adata
key, its value will be overwritten. Thedata
value will be created from the CSV file instead.options_kwargs (
dict
orNone
) –An optional
dict
containing keyword arguments that should be used when instantiating theHighchartsOptions
instance. Defaults toNone
.Warning
If
options_kwargs
contains aseries
key, theseries
value will be overwritten. Theseries
value will be created from the CSV file instead.An optional
dict
containing keyword arguments that should be used when instantiating theChart
instance. Defaults toNone
.Warning
If
chart_kwargs
contains anoptions
key,options
will be overwritten. Theoptions
value will be created from theoptions_kwargs
and CSV file instead.delimiter (
str
) – The delimiter used between columns. Defaults to,
.wrapper_character (
str
) – The string used to wrap string values when wrapping is applied. Defaults to'
.null_text (
str
) – The string used to indicate an empty value if empty values are wrapped. Defaults to None.line_terminator (
str
) –The string used to indicate the end of a line/record in the CSV data. Defaults to
'\r\n'
.Note
The Python
csv
currently ignores theline_terminator
parameter and always applies'\r\n'
, by design. The Python docs say this may change in the future, so for future backwards compatibility we are including it here.wrap_all_strings (
bool
) –If
True
, indicates that the CSV file has all string data values wrapped in quotation marks. Defaults toFalse
.double_wrapper_character_when_nested (
bool
) – IfTrue
, quote character is doubled when appearing within a string value. IfFalse
, theescape_character
is used to prefix quotation marks. Defaults toFalse
.escape_character (
str
) – A one-character string that indicates the character used to escape quotation marks if they appear within a string value that is already wrapped in quotation marks. Defaults to\\
(which is Python for'\'
, which is Python’s native escape character).is_maps_chart (
bool
) – IfTrue
, indicates that the chart should be instantiated as a Highcharts Stock for Python chart. Defaults toFalse
.
- Returns:
A
Chart
instance with its data populated from the CSV data.- Return type:
- Raises:
HighchartsCSVDeserializationError – if
property_column_map
references CSV columns by their label, but the CSV data does not contain a header row
- classmethod from_dict(as_dict: dict, allow_snake_case: bool = True)
Construct an instance of the class from a
dict
object.
- classmethod from_geopandas(gdf, property_map, series_type, series_kwargs=None, options_kwargs=None, chart_kwargs=None)[source]
Create a
Chart
instance whose data is populated from a geopandasGeoDataFrame
.- Parameters:
gdf (
GeoDataFrame
) – TheGeoDataFrame
from which data should be loaded.property_map (
dict
) – Adict
used to indicate which data point property should be set to which column ingdf
. The keys in thedict
should correspond to properties in the data point class, while the value should indicate the label for theGeoDataFrame
column.series_type (
str
) – Indicates the series type that should be created from the data ingdf
.series_kwargs (
dict
) –An optional
dict
containing keyword arguments that should be used when instantiating the series instance. Defaults toNone
.Warning
If
series_kwargs
contains adata
key, its value will be overwritten. Thedata
value will be created fromgdf
instead.options_kwargs (
dict
orNone
) –An optional
dict
containing keyword arguments that should be used when instantiating theHighchartsOptions
instance. Defaults toNone
.Warning
If
options_kwargs
contains aseries
key, theseries
value will be overwritten. Theseries
value will be created from the data ingdf
.An optional
dict
containing keyword arguments that should be used when instantiating theChart
instance. Defaults toNone
.Warning
If
chart_kwargs
contains anoptions
key,options
will be overwritten. Theoptions
value will be created from theoptions_kwargs
and the data ingdf
instead.
- Returns:
A
Chart
instance with its data populated from the data ingdf
.- Return type:
- Raises:
HighchartsPandasDeserializationError – if
property_map
references a column that does not exist in the data frameHighchartsDependencyError – if pandas is not available in the runtime environment
- 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
- classmethod from_map_data(map_data, options_kwargs=None, chart_kwargs=None)[source]
Create a
Chart
instance from aMapData
orAsyncMapData
object.- Parameters:
map_data (
MapData
orAsyncMapData
orNone
) –The map geometries to set. Accepts:
GeoJSONBase
or descendanta
str
URL, which will be coerced toAsyncMapData
options_kwargs (
dict
orNone
) –An optional
dict
containing keyword arguments that should be used when instanting the options for theChart
instance. Defaults toNone
Warning
If
options_kwargs
contains achart.map
setting, that value will be overwritten by the contents ofmap_data
.An optional
dict
containing keyword arguments that should be used when instantiating the instance. Defaults toNone
.Warning
If
chart_kwargs
contains anoptions
setting, that value will be overwritten by the options implied byoptions_kwargs
- Returns:
The
Chart
instance- Return type:
- classmethod from_options(options, chart_kwargs=None)[source]
Create a
Chart
instance from aHighchartsOptions
orHighchartsMapsOptions
object.- Parameters:
options (
HighchartsOptions
or related or coercable) – The configuration options to use to instantiate the chart.An optional
dict
containing keyword arguments that should be used when instantiating the instance. Defaults toNone
.Warning
If
chart_kwargs
contains anoptions
key,options
will be overwritten by the contents ofoptions
.
- Returns:
The
Chart
instance- Return type:
- classmethod from_pandas(df, property_map, series_type, series_kwargs=None, options_kwargs=None, chart_kwargs=None)[source]
Create a
Chart
instance whose data is populated from a pandasDataFrame
.- Parameters:
df (
DataFrame
) – TheDataFrame
from which data should be loaded.property_map (
dict
) – Adict
used to indicate which data point property should be set to which column indf
. The keys in thedict
should correspond to properties in the data point class, while the value should indicate the label for theDataFrame
column.series_type (
str
) – Indicates the series type that should be created from the data indf
.series_kwargs (
dict
) –An optional
dict
containing keyword arguments that should be used when instantiating the series instance. Defaults toNone
.Warning
If
series_kwargs
contains adata
key, its value will be overwritten. Thedata
value will be created fromdf
instead.options_kwargs (
dict
orNone
) –An optional
dict
containing keyword arguments that should be used when instantiating theHighchartsOptions
instance. Defaults toNone
.Warning
If
options_kwargs
contains aseries
key, theseries
value will be overwritten. Theseries
value will be created from the data indf
.An optional
dict
containing keyword arguments that should be used when instantiating theChart
instance. Defaults toNone
.Warning
If
chart_kwargs
contains anoptions
key,options
will be overwritten. Theoptions
value will be created from theoptions_kwargs
and the data indf
instead.
- Returns:
A
Chart
instance with its data populated from the data indf
.- Return type:
- Raises:
HighchartsPandasDeserializationError – if
property_map
references a column that does not exist in the data frameif pandas is not available in the runtime environment
- classmethod from_pyspark(df, property_map, series_type, series_kwargs=None, options_kwargs=None, chart_kwargs=None)[source]
Create a
Chart
instance whose data is populated from a PySparkDataFrame
.- Parameters:
df (
DataFrame
) – TheDataFrame
from which data should be loaded.property_map (
dict
) – Adict
used to indicate which data point property should be set to which column indf
. The keys in thedict
should correspond to properties in the data point class, while the value should indicate the label for theDataFrame
column.series_type (
str
) – Indicates the series type that should be created from the data indf
.series_kwargs (
dict
) –An optional
dict
containing keyword arguments that should be used when instantiating the series instance. Defaults toNone
.Warning
If
series_kwargs
contains adata
key, its value will be overwritten. Thedata
value will be created fromdf
instead.options_kwargs (
dict
orNone
) –An optional
dict
containing keyword arguments that should be used when instantiating theHighchartsOptions
instance. Defaults toNone
.Warning
If
options_kwargs
contains aseries
key, theseries
value will be overwritten. Theseries
value will be created from the data indf
.An optional
dict
containing keyword arguments that should be used when instantiating theChart
instance. Defaults toNone
.Warning
If
chart_kwargs
contains anoptions
key,options
will be overwritten. Theoptions
value will be created from theoptions_kwargs
and the data indf
instead.
- Returns:
A
Chart
instance with its data populated from the data indf
.- Return type:
- Raises:
HighchartsPySparkDeserializationError – if
property_map
references a column that does not exist in the data frameif PySpark is not available in the runtime environment
- classmethod from_series(*series, kwargs=None)[source]
Creates a new
Chart
instance populated withseries
.- Parameters:
series (one or more
SeriesBase
orIndicatorSeriesBase
coercable) – One or more series instances (descended fromSeriesBase
) or an instance (e.g.dict
,str
, etc.) coercable to onekwargs (
dict
) –Other properties to use as keyword arguments for the instance to be created.
Warning
If
kwargs
sets theoptions.series
property, that setting will be overridden by the contents ofseries
.
- Returns:
A new
Chart
instance- Return type:
- set_custom_projection(projection)[source]
Applies a custom map projection to the chart.
- Parameters:
projection (
CustomProjection
) – The custom projection definition to apply.
- set_map_data(map_data)[source]
Sets the default map geometries for the chart.
- Parameters:
map_data (
MapData
orAsyncMapData
orNone
) –The map geometries to set. Accepts:
GeoJSONBase
or descendanta
str
URL, which will be coerced toAsyncMapData
- 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') str | None [source]
Return the object represented as a
str
containing the JavaScript object literal.- Parameters:
Note
If
variable_name
is set, will render a string as a new JavaScript instance invocation in the (pseudo-code) form:new VARIABLE_NAME = new Chart(...);
If
variable_name
is not set, will simply return thenew Chart(...)
portion in the string.
- 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) dict
Remove keys from
untrimmed
whose values areNone
and convert values that have.to_dict()
methods.
- static trim_iterable(untrimmed, to_json=False)
Convert any
EnforcedNullType
values inuntrimmed
to'null'
.
- update_series(*series, add_if_unmatched=False)[source]
Replace existing series with the new versions supplied in
series
, matching them based on their.id
property.- Parameters:
series (one or more
SeriesBase
or coercable) – One or more series instances (descended fromSeriesBase
) or an instance (e.g.dict
,str
, etc.) coercable to oneadd_if_unmatched (
bool
) – IfTrue
, will add a series that does not have a match. IfFalse
, will raise aHighchartsMissingSeriesError
if a series does not have a match on the chart. Defaults toFalse
.
- property callback: CallbackFunction | None
A (JavaScript) function that is run when the chart has loaded and all external images have been loaded. Defaults to
None
.Note
Setting this proprety is equivalent to setting a value for
ChartOptions.events.load
- Return type:
CallbackFunction
orNone
- property container: str | None
The
id
of the<div>
element in which your Highcharts chart should be rendered. Defaults toNone
.
- property is_async: bool
Read-only property which indicates whether the data visualization should be rendered using asynchronous logic.
Note
This property will only return
True
if one or more series rely onAsyncMapData
- Return type:
- property is_maps_chart: bool
If
True
, indicates that the chart should be rendered as a Highcharts Maps chart. IfFalse
, the chart will be rendered using the standard Highcharts JS constructor. Defaults toFalse
.- Return type:
- property options: HighchartsOptions | HighchartsMapsOptions | None
The Python representation of the Highcharts Maps
options
configuration object Defaults toNone
.- Return type:
HighchartsOptions
orHighchartsMapsOptions
orNone
- property uses_custom_projection: bool
Read-only property which indicates whether the map visualization applies a custom projection.
Note
This property will only return
True
if theoptions.map_views.projection.custom
property is set.- Return type:
- property variable_name: str | None
The name given to the (JavaScript) variable to which the (JavaScript) Chart instance wil be assigned. Defaults to
None
.Note
When the
Chart
object is converted to JavaScript code, the (JavaScript) chart instance is assigned to a variable in your JavaScript code. In the example code below, the Chart instance is assigned to avariable_name
ofchart1
:var chart1 = Highcharts.Chart('myTargetDiv', {});