Overview
amCharts 5 provides flexible methods for loading data into your charts. You can set data directly, load it from external files, or fetch it from remote APIs.Setting Data Directly
The most straightforward way to add data to a chart is by using thedata property on series and other components.
Using setAll()
ThesetAll() method replaces all existing data with a new array:
data property is a ListData object that extends the List class. It automatically manages data items and triggers updates when data changes.
Using push()
Add individual data items to the end of the existing data:Other List Methods
Thedata property supports various list manipulation methods:
Loading External Data
amCharts 5 includes anet.load() utility function for loading data from external sources.
Basic Usage
Thenet.load() function returns a Promise that resolves with the loaded data:
Response Object
Thenet.load() function returns an INetLoadResult object with the following properties:
xhr: Reference to the original XMLHttpRequestresponse: Response body as a stringblob: Response as Blob (ifresponseTypeis set to “blob”)type: Response Content-Type headererror: Boolean indicating if there was an errortarget: Optional target object that made the request
Request Options
You can customize the request with options:requestHeaders: Array of custom HTTP headersresponseType: Expected response type (e.g., “json”, “blob”, “text”)withCredentials: Send cookies with cross-origin requests (default: false)
Error Handling
Loading from CSV or JSON Files
For structured data formats, combinenet.load() with data parsers:
Data Structure Requirements
Each series type requires specific fields in the data:XY Series
Flow Diagrams
Performance Considerations
Large Datasets
When loading large datasets:- Use
setAll()instead of multiplepush()calls for better performance - Consider data grouping for time-based data
- Enable data processor only when needed
Lazy Loading
For very large datasets, consider loading data in chunks:Related Topics
- Parsing Data - Parse CSV, JSON, and other formats
- Processing Data - Transform and process data
- Live Data - Update charts in real-time