Data Providers
Overview
Data Provider defines a subset of the CSV data table provided by some data set. Each data provider
has the unique id and is bound to the given data set. Data Provider gets one or several columns in the data set.
Certain series types require data providers with certain columns.
Declaration
Data Provider is used to define what columns from the Data Set are used by series to show the chart or
calculate and chart the technical indicator.
Sample
XML syntax for Data Providers looks like:
01 |
<?xml version="1.0" encoding="UTF-8"?> |
02 |
< stock xmlns = "http://anychart.com/products/stock/schemas/1.9.0/schema.xsd" > |
As you can see two data providers are defined using <data_provider> nodes with the following attributes set:
Attributes |
Description |
data_set |
Sets Data Set id. This attribute is required. |
id |
Unique identifier of Data Provider. This attribute is required and is used by series. |
See other data provider attributes in XML Reference.
Fields
Data providers defines the columns from the data set that are used by a series. In data provider the
columns become fields. This selection is set in <field> subnode of <fields> node.
Sample <field> declaration:
01 |
<?xml version="1.0" encoding="UTF-8"?> |
02 |
< stock xmlns = "http://anychart.com/products/stock/schemas/1.9.0/schema.xsd" > |
Two basic attributes are required to declare a field:
Attributes |
Possible values |
Description |
type |
Low
High
Open
Close
Value
Volume
Custom
Text
DateTime |
Sets the type of the column. All single-value series and some technical indicators require a column with "Value" or "Close" type ("Value" column has higher priority). Some technical indicators, such as PSAR require "High" and "Low" columns. All series with 4 values require "Open", "Close", "High" and "Low" columns. Read more in Creating Series article.
For the numeric custom fields: use "Custom" column type.
For the non-numeric data - please use "Text" column type.
For the formattable date time - use "DateTime" column type.
The last three types require a name specified in custom_type_name to be used in legend, tooltip, etc.
|
column |
Number |
Zero-based index of the column to which the field is bound. |
See other field attributes in XML Reference.
Custom Fields
Each series has the list of required fields - these are fields that
should exist in data provider to make series be drawn properly. The list of required fields can be found
in series description. But you can add any number of fields and use the
data from them in tooltips, labels or legend.
To do so you have to set type to "Custom" and define a name in custom_type_name, as shown in the sample XML below:
01 |
<?xml version="1.0" encoding="UTF-8"?> |
02 |
< stock xmlns = "http://anychart.com/products/stock/schemas/1.9.0/schema.xsd" > |
Sample usage of custom fields can be found at:
Text Fields
If you need to display some text associated with the data you can add any number of Text fields and use the
data from these fields in tooltips, labels or legend.
To do so you have to set type to "Text" and define a name in custom_type_name, as shown in the sample XML below:
01 |
<?xml version="1.0" encoding="UTF-8"?> |
02 |
< stock xmlns = "http://anychart.com/products/stock/schemas/1.9.0/schema.xsd" > |
Note: only "Open" and "Close" approximation types are available for text columns, please be careful when you use grouping along with Text fields - the result may lead to misrepresentation.
Sample usage of custom fields can be found at:
DateTime Fields
If you need to some additional formattable date time fields associated with the data you can add any number of DateTime fields and use the
data from these fields in tooltips, labels or legend.
To do so you have to set type to "DateTime", define a name in custom_type_name and specify the input format as shown in the sample XML below:
01 |
<?xml version="1.0" encoding="UTF-8"?> |
02 |
< stock xmlns = "http://anychart.com/products/stock/schemas/1.9.0/schema.xsd" > |
Note 1: input format specified in <date_time> is required if you want to use formatting options, if you omit this input format the field will be treated as Text field.
Note 2: DateTime columns support all types of approximation when grouped, but you should understand that values are approximated as numbers (unix timestamp) and then converted to the date.
Note 3: Locale settings, base_date and offset for DateTime columns are inherited from DataSet settings.
Sample usage of custom fields can be found at:
Scroller
Scroller is used to navigate through the chart and on most of the samples in documentation and in the gallery you can
see a small chart that is drawn in the background of the scroller. This chart is intended to make navigation easier and needs some configuration.
In short: you have to specify what data is used to draw this chart, which means - you have to specify data provider for it.
To define the data provider for scroller you have
to add <data_provider> into <scroller_data_providers> and specify what data
set and what column are used to build this small chart. The XML look like that:
To learn more about scroller data binding and configuration refer to:
Using Data Provider in Series
Data Providers are used by series, which are displayed on the chart, please see the article below to learn how to do that: