Type class
Represents a single data source - external file with all of its settings, such as format, data parsing, etc.
chart.dataSource.url = "http://www.myweb.com/data.json"; chart.dataSource.parser = am4core.JSONParser;
chart.dataSource.url = "http://www.myweb.com/data.json"; chart.dataSource.parser = am4core.JSONParser;
{ // ... "dataSource": { "url": "http://www.myweb.com/data.json", "parser": "JSONParser" }, // ... }
IDataSourceEvents
for a list of available events
IDataSourceAdapters
for a list of available Adapters
Sources
DataSource can be used (imported) via one of the following packages.
/** * -------------------------------------------------------- * Import from: "core.ts" * Use like: am4core.DataSource * -------------------------------------------------------- */ import * as am4core from "@amcharts/amcharts4/core";
/** * -------------------------------------------------------- * Include via: <script src="core.js"></script> * Access items like: am4.DataSource * -------------------------------------------------------- */
Inheritance
DataSource extends BaseObjectEvents
.
DataSource is not extended by any other symbol.
Properties
adapter # |
Type Default Adapter. |
---|---|
clonedFrom # |
Type Inherited from Reference to the original object this object was cloned from. We need to keep this so we can disassociate it from source object when this object is disposed. |
component # |
Type A |
config # |
Type Inherited from Use this property to set JSON-based config. When set, triggers processing routine, which will go through all properties, and try to apply values, create instances, etc. Use this with caution, as it is a time-consuming process. It's used for initialchart setup only, not routine operations. |
data # |
Type Loaded and parsed data. |
dateFormatter # |
Type A Will inherit and use chart's DateFormatter if not ser. |
disableCache # |
Type If set to |
events # |
Type Inherited from An |
id # |
Type Inherited from Sets the user-defined id of the element. |
incremental # |
Type Default Should subsequent reloads be treated as incremental? Incremental loads will assume that they contain only new data items since the last load. If This setting does not have any effect trhe first time data is loaded. NOTE: this setting works only with element's |
incrementalParams # |
Type An object consisting of key/value pairs to apply to an URL when data source is making an incremental request. |
keepCount # |
Type Default This setting is used only when E.g. if incremental load yeilded 5 new records, then 5 items from the beginning of data will be removed so that we end up with the same number of data items. |
language # |
Type Language instance to use. Will inherit and use chart's language, if not set. |
lastLoad # |
Type Holds the date of the last load. |
parser # |
Type Default A parser to be used to parse data. chart.dataSource.url = "http://www.myweb.com/data.json"; chart.dataSource.parser = am4core.JSONParser; chart.dataSource.url = "http://www.myweb.com/data.json"; chart.dataSource.parser = am4core.JSONParser; { // ... "dataSource": { "url": "http://www.myweb.com/data.json", "parser": { "type": "JSONParser" } }, // ... } |
reloadFrequency # |
Type Data source reload frequency. If set, it will reload the same URL every X milliseconds. |
requestOptions # |
Type Custom options for HTTP(S) request. At this moment the only option supported is: chart.dataSource.requestOptions.requestHeaders = [{ "key": "x-access-token", "value": "123456789" }]; chart.dataSource.requestOptions.requestHeaders = [{ "key": "x-access-token", "value": "123456789" }]; { // ... "dataSource": { // ... "requestOptions": { "requestHeaders": [{ "key": "x-access-token", "value": "123456789" }] } } } NOTE: setting this options on an-already loaded DataSource will not trigger a reload. |
showPreloader # |
Type Default Will show loading indicator when loading files. |
uid # |
Type Inherited from Returns object's internal unique ID. |
updateCurrentData # |
Type Default If set to This will work faster than complete update, and also will animate the values to their new positions. Data sources across loads must contain the same number of data items. Loader will not truncate the data set if loaded data has fewer data items, and if it is longer, the excess data items will be ignored. NOTE: this setting is ignored if @since 2.5.5 |
url # |
Type URL of the data source. |
There are 5 inherited items currently hidden from this list. |
Methods
addUrlParams( url: ) |
Returns Adds parameters to |
---|---|
clone( cloneId?: ) |
Returns Inherited from Makes a copy of this object and returns the clone. Try to avoid cloning complex objects like chart, create new instances if you need them. |
constructor( url?: ) |
Returns Constructor |
copyFrom( source: ) |
Returns Inherited from Copies all parameters from another |
dispatch( eventType: ) |
Returns Inherited from Dispatches an event using own event dispatcher. Will automatically populate event data object with event type and target (this element). It also checks if there are any handlers registered for this sepecific event. |
dispatchImmediately( eventType: ) |
Returns Inherited from Works like |
dispose() |
Returns Disposes of this object. |
getCurrentThemes() |
Returns Inherited from Returns a list of themes that should be applied to this element. It could either be a list of themes set explicitly on this element, or system-wide. |
isDisposed() |
Returns Inherited from Returns if this object has been already been disposed. |
load() |
Returns Initiate the load. All loading in JavaScript is asynchronous. This function will trigger the load and will exit immediately. Use DataSource's events to watch for loaded data and errors. |
timestampUrl( url: ) |
Returns Adds current timestamp to the URL. |
There are 6 inherited items currently hidden from this list. |
Events
#done |
Param { data: Invoked when data source was successfully loaded and parsed. |
---|---|
#ended |
Param { type: Invoked when loading and parsing finishes. |
#error |
Param { code: Invoked when data source encounters a loading error. |
#loadended |
Param { type: Invoked when the loading of the data finishes. |
#loadstarted |
Param { type: Invoked when loading of the data starts. |
#parseended |
Param { type: Invoked when parsing of the loaded data finishes. |
#parseerror |
Param { message: Invoked when data source encounters a parsing error. |
#parsestarted |
Param { type: Invoked when parsing of the loaded data starts. |
#started |
Param { type: Invoked when loading of the data starts. |
Adapters
#dateFields |
Param Applied to the array that lists fields in data that hold date-based values. |
---|---|
#incremental |
Param Applied to |
#incrementalParams |
Param Applied to |
#keepCount |
Param Applied to |
#numberFields |
Param Applied to the array that lists fields in data that hold numeric values. |
#parsedData |
Param Applied to the loaded data after it was parsed by a parser. |
#parser |
Param Applied to a parser type, before parsing starts. Can be used to supply different parser than the one set/determined by Data Loader. |
#parserOptions |
Param Applied to parser options. |
#reloadTimeout |
Param Applied to the timeout setting. |
#requestOptions |
Param Applied to the custom request options object. |
#unparsedData |
Param Applied to the loaded data before it is passed to parser. |
#updateCurrentData |
Param Applied to |
#url |
Param Applied to a data source URL before it is loaded. |