.data
class: Data
- class Data(**kwargs)[source]
The
dataproperty provides a simplified interface for adding data to a chart from sources like CVS, HTML tables, or grid views. See also the tutorial article on the Data module.Warning
It requires the
modules/data.jsfile to be loaded in the browser / client.Warning
Please note that the default way of adding data in Highcharts, without the need of a module, is through the
series.dataproperty.Class Inheritance

- copy(other=None, overwrite=True, **kwargs)
Copy the configuration settings from this instance to the
otherinstance.- 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 inotherthat are already set will be overwritten by their counterparts inself. Defaults toTrue.kwargs – Additional keyword arguments. Some special descendents of
HighchartsMetamay have special implementations of this method which rely on additional keyword arguments.
- Returns:
A mutated version of
otherwith new property values
- classmethod from_dict(as_dict: dict, allow_snake_case: bool = True)
Construct an instance of the class from a
dictobject.
- 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 astror as a filename which contains the JS object literal.allow_snake_case (
bool) – IfTrue, interpretssnake_casekeys as equivalent tocamelCasekeys. 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_casekeys as equivalent tocamelCasekeys. Defaults toTrue.
- Returns:
A Python objcet representation of
as_json.- Return type:
HighchartsMeta
- classmethod from_pandas(as_df, represent_as='csv', data_kwargs=None, pandas_kwargs=None)[source]
Create a
Datainstance from a PandasDataFrame <pandas:DataFrame.- Parameters:
as_df (
DataFrame) – TheDataFramefrom which to create theDatainstance.represent_as (
str) – The format to whichas_dfshould be serialized. Accepts'csv'or'html'. Defaults to'csv'.data_kwargs (
dict) – Additional keyword arguments to pass to theDataconstructor (__init__()) method. Defaults toNone.pandas_kwargs (
dict) – Keyword arguments to pass to the PandasDataFrame.to_csv()orDataFrame.to_html()methods. Defaults toNone.
Note
To prevent unexpected behavior, if
represent_asis set to'csv', theData.table()property will be set toNone. Ifrepresent_asis set to'html', theData.csv()property will be set toNone.- Returns:
A
Datainstance.
- classmethod from_pyspark(as_df, data_kwargs=None, pyspark_kwargs=None, consolidation='repartition')[source]
Create a
Datainstance from a PySparkDataFrame.Warning
If you are using PySpark, you might be working with extremely large datasets (proverbial “big data”). Are you sure you want to be visualizing datasets of such size? If so, you should be aware that Highcharts for Python tries to store the dataset in the Python environment’s memory - not on disk.
If you need to read large datasets from disk, using the
Data.from_pyspark()is not recommended for this reason.- Parameters:
as_df (
pyspark.sql.DataFrame) – TheDataFramefrom which to create theDatainstance.data_kwargs (
dict) –Additional keyword arguments to pass to the
Dataconstructor (__init__()) method. Defaults toNone.Warning
The
Data.csv()andData.table()properties will be overwritten by Highcharts for Python if specified, so don’t bother.pyspark_kwargs (
dict) –Keyword arguments to pass to the Pyspark
DataFrame.write().csv()method. Defaults toNone.Warning
The
pathandmodearguments will be overwritten by Highcharts for Python if specified, so don’t bother.consolidation –
If
'repartition', will repartition your PySparkDataFrameinto a single unpartitioned table prior to the generation of a CSV dataset. If'coalesce', will coalesce your PySparkDataFrameinto a single unpartitioned table prior to the generation of a CSV dataset. IfNone, will not apply any consolidation to theDataFrame. Defaults to'coalesce'.Hint
Setting this value to
'coalesce'is particularly useful if you are working on yourDataFramein multiple Spark nodes to prevent loss of data.Setting this value to
Nonemay provide a boost to performance, however use with caution as it may lead to unexpected data loss or errors if using multiple Spark nodes.
- Returns:
A
Datainstance.
- to_dict() dict
Generate a
dictrepresentation of the object compatible with the Highcharts JavaScript library.Note
The
dictrepresentation 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
Return the object represented as a
strcontaining the JavaScript object literal.
- 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
stror abytesobject depending on the JSON serialization library you are using. For example, if your environment has orjson, the result will be abytesrepresentation 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
untrimmedwhose values areNoneand convert values that have.to_dict()methods.
- static trim_iterable(untrimmed, to_json=False)
Convert any
EnforcedNullTypevalues inuntrimmedto'null'.
- property before_parse: CallbackFunction | None
A JavaScript callback function that is used to modify the CSV data before it is parsed. The function should return a modified version of the CSV string. Defaults to
None.- Return type:
CallbackFunctionorNone
- property columns: List[List[int | str | float | Decimal | None | EnforcedNullType]] | None
The data itself represented in a tabular form. Expects an iterable of iterables, where each second-level iterable represents a column of data. Defaults to
None.my_data = Data() my_data.columns = [ [None, 'Apples', 'Pears', 'Oranges'], # categories ['Ola', 1, 4, 3], # first series for "Ola" ['Kari', 5, 4, 2] # second series for "Kari" ]
Note
Each cell in the second-level iterable can either be a
str, numeric value,None, orEnforcedNullType.Hint
Provided that
Data.switch_rows_and_columns()is not set, the columns will be interpreted as series.
- property columns_url
A URL to a remote JSON dataset, structured as a column array. Defaults to
None.Note
Will be fetched when the chart is created using Ajax.
- property complete: CallbackFunction | None
The JavaScript callback function that is evaluated when the data has finished loading (optionally from an external source) and been parsed. The first argument passed is a finished chart options object, containing the series. These options can be extended with additional options and passed directly to the chart constructor. Defaults to
None.- Return type:
CallbackFunctionorNone
- property csv: str | None
A comma-delimited string to be parsed. Defaults to
None.See also
The object has closely-related properties that determine which part of the CSV string should be used when constructing the chart and to configure how the CSV string should be parsed. In particular, please review:
Warning
The built-in CSV parser does not support all flavours of CSV, so in some cases it may be necessary to use an external CSV parser. See this example of parsing a CSV through the MIT-licensed Papa Parse library.
- property csv_url
A URL to a remote CSV dataset. Defaults to
None.Note
Will be fetched when the chart is created using Ajax.
- property data_refresh_rate: int | float | Decimal | None
The number of seconds between each poll of data from a remote source configured using either
Data.columns_url(),Data.csv_url(),Data.rows_url(), orData.google_spreadsheet_key(). Defaults to1.Warning
Cannot be set to less than
1.Note
For polling to be enabled,
Data.enable_polling()must beTrue.- Return type:
numeric or
None
- property date_format: str | None
Indicates the format string to use to parse date values. If
None, defaults to a best-guess based on what format gives valid and ordered dates. Defaults toNone.Valid options include:
'YYYY/mm/dd''dd/mm/YYYY''mm/dd/YYYY''dd/mm/YY''mm/dd/YY'
- property decimal_point: str | None
The decimal point used when parsing number values. Defaults to
'.'ifNone.Note
If both
decimal_pointandData.delimiter()are set toNone, the parser will attempt to deduce the decimal point automatically.- Return type:
- property enable_polling: bool | None
If
True, automatically re-fetches remote datasets every n seconds (as perData.data_refresh_rate()). Defaults toFalse.Note
This flag only has an impact if remote datasets are in use, as specified by any one of:
- property end_column: int | None
In tabular input data, the last column (indexed by
0) to use. IfNone, defaults to the last column that contains data.
- property end_row: int | None
In tabular input data, the last row (indexed by
0) to use. IfNone, defaults to the last row that contains data.
- property first_row_as_names: bool | None
If
True, use the first row of data as series names. Defaults toTrue.
- property google_api_key: str | None
The Google Spreadsheet API key required for access. Defaults to
None.Note
Be sure to generate your Google Spreadsheet API key at Google’s API Services / Credentials.
Warning
To load data from Google Sheets, the
Data.google_spreadsheet_key()must be set, and must have access to the spreadsheet indicated by the spreadsheet key.
- property google_spreadsheet_key: str | None
The key or
spreadsheetIdvalue for the Google Sheets spreadsheet from which you wish to load data. Defaults toNone.Hint
If you need help finding your spreadsheet key, please review the Google Sheets API Overview
Warning
To load data from Google Sheets, the
Data.google_api_key()must be set, and must have access to the spreadsheet indicated by the spreadsheet key.
- property google_spreadsheet_range: str | None
The Google Sheets A1 or R1C1 notation cell range from which to retrieve data. Defaults to
None.Note
If set, this property takes precedence over
Data.start_column(),Data.end_column(),Data.start_row(), andData.end_row().Hint
For more details on how to determine and provide the spreadsheet range, please review the relevant Google Sheets API documentation.
Warning
To load data from Google Sheets, the
Data.google_api_key()andData.google_spreadsheet_key()must both be set.
- property item_delimiter: bool | str | None
Item or cell delimiter used when parsing CSV data. If
NoneorFalse, defaults to the tab character `` `` if a tab character is found in the CSV string. If no tab character is found, defaults to','.
- property line_delimiter: str | None
The string used to delimit records (lines) when parsing CSV data. Defaults to
None, which assumes'\n'.
- property parse_date: CallbackFunction | None
A JavaScript callback function to parse string representations of dates into JavaScript timestamps. Should return an integer timestamp on success. Defaults to
None.- Return type:
CallbackFunctionorNone
- property parsed: CallbackFunction | None
A JavaScript callback function to access the parsed columns (the two-dimentional input data array) directly before they are interpreted into series data and categories. The function should return
falseto stop completion, or call (in JavaScript)this.complete()to continue asynchronously. Defaults toNone.- Return type:
CallbackFunctionorNone
- property rows: List[List[int | str | float | Decimal | None | EnforcedNullType]] | None
The data itself represented in a tabular form. Expects an iterable of iterables, where each second-level iterable represents a row of data. Defaults to
None.my_data = Data() my_data.rows = [ [None, 'Apples', 'Pears', 'Oranges'], # categories ['Ola', 1, 4, 3], # first series for "Ola" ['Kari', 5, 4, 2] # second series for "Kari" ]
Note
Each cell in the second-level iterable can either be a
str, numeric value,None, orEnforcedNullType.Hint
Provided that
Data.switch_rows_and_columns()is not set, the rows will be interpreted as series.
- property rows_url
A URL to a remote JSON dataset, structured as a row array. Defaults to
None.Note
Will be fetched when the chart is created using Ajax.
- property series_mapping: dict[str, int] | None
A dictionary used to indicate where point properties are to be found in the data. Property names are the keys, while the values are the column indices indicating where in the CSV the data for that point is to be found. Defaults to
None.
- property start_column: int | None
In tabular input data, the first column (indexed by
0) to use. IfNone, defaults to0.
- property start_row: int | None
In tabular input data, the first row (indexed by
0) to use. IfNone, defaults to0.
- property switch_rows_and_columns: bool | None
If
True, swiches the interpretation of columns and rows so thatData.columns()effectively becomes rows of the data whileData.rows()is interpreted as the series of data. Defaults toFalse.
- property table: str | None
An HTML table (in
strform), or the ID of such a table found in the browser DOM, which should be parsed to extract the data intended for visualization. Defaults toNone.See also
The object has closely-related properties that determine which part of the HTML table should be used when constructing the chart and to configure how the table string should be parsed. In particular, please review: