namespace anychart.data Improve this Doc
Classes for handling data structures/sources
The following data types/hierarchy is supported:
- Linear (anychart.data.Set and anychart.data.Mapping)
- Tree (anychart.data.Tree)
Functions Overview
buildMapping() | Creates data mapping. |
loadCsvFile() | Loads the CSV file. |
loadGoogleSpreadsheet() | Loads the Google Spreadsheets. |
loadJsonFile() | Loads the JSON file. |
loadXmlFile() | Loads the XML file. |
mapAsTable() | Maps passed data as an array of mappings. |
parseHtmlTable() | Parses HTML table to table data. |
parseText() | Text parsing. |
set() | Return instance of class anychart.data.Set. |
table() | Creates and returns a new instance of a data table. |
tree() | Creates and returns a new instance of the data tree. |
Typedefs Overview
anychart.data.DataSettings | Type definition for table data. |
anychart.data.TextParsingSettings | Settings for parsing text. |
Classes Overview
anychart.data.Iterator | anychart.data.Iterator class is used to work with data in a View. |
anychart.data.Mapping | The special view which allows mapping anychart.data.Set storages. |
anychart.data.Set | Linear data storage. |
anychart.data.Table | Stock data table constructor. |
anychart.data.TableComputer | Stock table computer constructor. |
anychart.data.TableComputer.RowProxy | Row proxy for computational functions. |
anychart.data.TableIterator | Table iterator class. Assumes iterator (if any) to return not fewer keys than the table has. |
anychart.data.TableMapping | Table mapping constructor. |
anychart.data.TableSelectable | Table mapping proxy that supports selection |
anychart.data.TableSelectable.RowProxy | Represents table row with associated mapping. Allows fetching rows values. |
anychart.data.Traverser | Tree data traverser. |
anychart.data.Tree | Tree data model. |
anychart.data.Tree.DataItem | Tree data item. |
anychart.data.TreeView | TreeView. Class of mapped tree. |
anychart.data.TreeView.DataItem | Mapped data item class. |
anychart.data.View | View is a representation of raw data. |
Functions Description
buildMapping
Creates data mapping.
Creates object mapping if keys are set, otherwise - array mapping.
Creates object mapping if keys are set, otherwise - array mapping.
Params:
Name | Type | Description |
---|---|---|
dataSet | anychart.data.Set | Data set |
fromIndex | number | "From" index |
toIndex | number | "To" index |
names | Array.<string> | Field names |
keys | Array.<string> | Keys |
Returns:
anychart.data.Mapping - Returns an object mapping.Try it:
loadCsvFile
Loads the CSV file.
Detailed description
To work with the data adapter you need to reference the data adapter script file from AnyChart CDN
(https://cdn.anychart.com/releases/8.13.0/js/anychart-data-adapter.min.js for latest or https://cdn.anychart.com/releases/8.13.0/js/anychart-data-adapter.min.js for the versioned file)
Params:
Name | Type | Description |
---|---|---|
url | string | URL of an CSV file or a script |
onSuccess | function(data:Array.<string>) | The function that is launched after chart is successfully loaded. Takes resulting data object parsed from response string as an argument. |
onError | function(errorCode:number, exceptionOrMessage:Object|string) | Function that is called if loading fails. Takes an error code as first argument and exception object or error message as the second argument. |
method | string | Send method |
content | ArrayBuffer | ArrayBufferView | Blob | Document | FormData | string | Data |
headers | Object | Headers to add to the request |
timeoutInterval | number | Number of milliseconds after which an incomplete request is aborted |
withCredentials | boolean | Whether to send credentials with the request |
context | * | Context for handler function |
Try it:
loadGoogleSpreadsheet
Loads the Google Spreadsheets.
Learn more about loading Google Spreadsheet
Detailed description
To work with the data adapter you need to reference the data adapter script file from AnyChart CDN
(https://cdn.anychart.com/releases/8.13.0/js/anychart-data-adapter.min.js for latest or https://cdn.anychart.com/releases/8.13.0/js/anychart-data-adapter.min.js for the versioned file)
Params:
Name | Type | Description |
---|---|---|
key | string | Object | Google Spreadsheet key. |
onSuccess | function(data:anychart.data.DataSettings, settings:Object) | The function that is launched after chart is successfully loaded. Takes resulting data object parsed from response string as an argument. |
onError | function | The function that is launched if chart loading fails. |
timeoutInterval | number | Number of milliseconds after which an incomplete request is aborted. |
context | * | Context for handler function. |
Try it:
loadJsonFile
Loads the JSON file.
Detailed description
To work with the data adapter you need to reference the data adapter script file from AnyChart CDN
(https://cdn.anychart.com/releases/8.13.0/js/anychart-data-adapter.min.js for latest or https://cdn.anychart.com/releases/8.13.0/js/anychart-data-adapter.min.js for the versioned file)
Params:
Name | Type | Description |
---|---|---|
url | string | URL of a JSON file or a script. |
onSuccess | function(data:Array.<(Object|string|number|boolean|null)>) | The function that is launched after chart is successfully loaded. Takes resulting data object parsed from response string as an argument. |
onError | function(errorCode:number, errorMessage:string) | Function that is called if loading fails. Takes an error code as first argument and exception object or error message as the second argument. |
method | string | Send method |
content | ArrayBuffer | ArrayBufferView | Blob | Document | FormData | string | Data. |
headers | Object | Headers to add to the request |
timeoutInterval | number | Number of milliseconds after which an incomplete request is aborted |
withCredentials | boolean | Whether to send credentials with the request |
context | * | Context for handler function |
Try it:
loadXmlFile
Loads the XML file.
Detailed description
To work with the data adapter you need to reference the data adapter script file from AnyChart CDN
(https://cdn.anychart.com/releases/8.13.0/js/anychart-data-adapter.min.js for latest or https://cdn.anychart.com/releases/8.13.0/js/anychart-data-adapter.min.js for the versioned file)
Params:
Name | Type | Description |
---|---|---|
url | string | URL of an XML file or a script |
onSuccess | function(data:Object) | The function that is launched after chart is successfully loaded. Takes resulting data object parsed from response string as an argument. |
onError | function(errorCode:number, exceptionOrMessage:Object|string) | Function that is called if loading fails. Takes an error code as first argument and exception object or error message as the second argument. |
method | string | Send method |
content | ArrayBuffer | ArrayBufferView | Blob | Document | FormData | string | Data |
headers | Object | Headers to add to the request |
timeoutInterval | number | Number of milliseconds after which an incomplete request is aborted. |
withCredentials | boolean | Whether to send credentials with the request |
context | * | Context for handler function |
Try it:
mapAsTable
Maps passed data as an array of mappings.
Detailed description
Data is expected to be a table, e.g. an array of arrays of values.
The function treats the table as a source for several series of points, that have the same X value.
Each row of the table is treated as a bunch of points, one for each series. Column number 0 is treated as an X value.
Other columns (number per series depends on the opt_mode) are treated as data values.
Params:
Name | Type | Description |
---|---|---|
data | Array.<Array.<*>> | Source data table. |
mode | anychart.enums.MapAsTableMode | string | Mapping mode. |
seriesCount | number | Explicit number of series to make mapping for. If not set, auto-determination by the first table row is used. |
Returns:
Array.<anychart.data.Mapping> - Returns an array of mappings, one per series.parseHtmlTable
Parses HTML table to table data.
Params:
Name | Type | Description |
---|---|---|
tableSelector | string | CSS table selector |
rowsSelector | string | Rows selector in the CSS table |
cellsSelector | string | Cells selector in the CSS table |
headersSelector | string | Header selector in the CSS table |
captionSelector | string | Caption selector in the CSS table |
valueProcessor | function | Function that converts values from a table |
Returns:
anychart.data.DataSettings - Returns data settings.Try it:
parseText
Text parsing.
Params:
Name | Type | Description |
---|---|---|
text | string | Text to parsing. |
settings | anychart.enums.TextParsingMode | string | anychart.data.TextParsingSettings | Parsing settings. |
Returns:
Array.<Array.<(string|number)>> - Array of arrays.Try it:
set
Return instance of class anychart.data.Set.
Params:
Name | Type | Description |
---|---|---|
data | Array | string | Dataset raw data can be set here. |
csvSettings | anychart.enums.TextParsingMode | string | anychart.data.TextParsingSettings | If CSV string is passed, you can pass CSV parser settings here as a hash map. |
Returns:
anychart.data.Set - Self instance for method chaining.Try it:
table
Creates and returns a new instance of a data table.
Key column index defaults to zero column.
Params:
Name | Type | Description |
---|---|---|
keyColumnIndex | number | string | Index of the column in with the table key field or field name in the array. |
dateTimePattern | string | Key column parsing pattern. |
timeOffset | number | Shifts all input dates timeOffset hours forward. Defaults to zero. |
baseDate | number | Date | Base date for the key column. |
locale | string | anychart.format.Locale | Locale to be used. |
Returns:
anychart.data.Table - Self instance for method chaining.Try it:
tree
Creates and returns a new instance of the data tree.
Params:
Name | Type | Description |
---|---|---|
data | Array.<Object> | string | Raw data or CSV-string. If the string is passed, the second parameter is interpreted as fields mapping. |
fillMethodOrCsvMapping | anychart.enums.TreeFillingMethod | Object | Fill method or CSV mapping object.
This parameter is interpreted as mapping object if the first parameter is a string. Mapping object should have the structure
like
//'nameOfField': index_of_column mapping = { 'id': 0, 'name': 1, 'value': 15 }; |
csvSettings | anychart.enums.TextParsingMode | string | anychart.data.TextParsingSettings | CSV settings object. Should be fields like rowsSeparator - string or undefined, if it is undefined, it will not be set. columnsSeparator - string or undefined, if it is undefined, it will not be set. ignoreTrailingSpaces - boolean or undefined, if it is undefined, it will not be set. ignoreFirstRow - boolean or undefined, if it is undefined, it will not be set. |
fieldsMapping | Object | Field mapping object. Maps only first-level data. |
Returns:
anychart.data.Tree - Self instance for method chaining.Try it: