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.

to top

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:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <data>
04     <data_providers>
05       <general_data_providers>
06         <data_provider data_set="dataSet1" id="s1">
07           <fields>
08             <field type="Value" column="4" />
09           </fields>
10         </data_provider>
11         <data_provider data_set="dataSet2" id="s2">
12           <fields>
13             <field type="Open" column="1" approximation_type="Open" />
14             <field type="High" column="2" approximation_type="High" />
15             <field type="Low" column="3" approximation_type="Low" />
16             <field type="Close" column="4" approximation_type="Close" />
17           </fields>
18         </data_provider>
19       </general_data_providers>
20     </data_providers>
21   </data>
22 </stock>
01{
02  data: {
03    dataProviders: {
04      generalDataProviders: [
05        {
06          dataSet: "dataSet1",
07          id: "s1",
08          fields: [
09            {
10              type: "Value",
11              column: 4
12            }
13          ]
14        },
15        {
16          dataSet: "dataSet2",
17          id: "s2",
18          fields: [
19            {
20              type: "Open",
21              column: 1,
22              approximationType: "Open"
23            },
24            {
25              type: "High",
26              column: 2,
27              approximationType: "High"
28            },
29            {
30              type: "Low",
31              column: 3,
32              approximationType: "Low"
33            },
34            {
35              type: "Close",
36              column: 4,
37              approximationType: "Close"
38            }
39          ]
40        }
41      ]
42    }
43  }
44}

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:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <data>
04     <data_providers>
05       <general_data_providers>
06         <data_provider>
07           <fields>
08             <field type="Open" column="1" approximation_type="Open" />
09             <field type="High" column="2" approximation_type="High" />
10             <field type="Low" column="3" approximation_type="Low" />
11             <field type="Close" column="4" approximation_type="Close" />
12           </fields>
13         </data_provider>
14       </general_data_providers>
15     </data_providers>
16   </data>
17 </stock>
01{
02  data: {
03    dataProviders: {
04      generalDataProviders: [
05        {
06          fields: [
07            {
08              type: "Open",
09              column: 1,
10              approximationType: "Open"
11            },
12            {
13              type: "High",
14              column: 2,
15              approximationType: "High"
16            },
17            {
18              type: "Low",
19              column: 3,
20              approximationType: "Low"
21            },
22            {
23              type: "Close",
24              column: 4,
25              approximationType: "Close"
26            }
27          ]
28        }
29      ]
30    }
31  }
32}

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.

to top

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:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <data>
04     <data_providers>
05       <general_data_providers>
06         <data_provider data_set="dataSet1" id="s1">
07           <fields>
08             <field type="Custom" custom_type_name="Profit" column="4" />
09             <field type="Custom" custom_type_name="Sales" column="5" />
10           </fields>
11         </data_provider>
12       </general_data_providers>
13     </data_providers>
14   </data>
15 </stock>
01{
02  data: {
03    dataProviders: {
04      generalDataProviders: [
05        {
06          dataSet: "dataSet1",
07          id: "s1",
08          fields: [
09            {
10              type: "Custom",
11              customTypeName: "Profit",
12              column: 4
13            },
14            {
15              type: "Custom",
16              customTypeName: "Sales",
17              column: 5
18            }
19          ]
20        }
21      ]
22    }
23  }
24}

Sample usage of custom fields can be found at:

to top

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:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <data>
04     <data_providers>
05       <general_data_providers>
06         <data_provider data_set="dataSet1" id="s1">
07           <fields>
08             <field type="Text" custom_type_name="Description" column="4" />
09             <field type="Text" custom_type_name="Note" column="5" />
10           </fields>
11         </data_provider>
12       </general_data_providers>
13     </data_providers>
14   </data>
15 </stock>
01{
02  data: {
03    dataProviders: {
04      generalDataProviders: [
05        {
06          dataSet: "dataSet1",
07          id: "s1",
08          fields: [
09            {
10              type: "Text",
11              customTypeName: "Description",
12              column: 4
13            },
14            {
15              type: "Text",
16              customTypeName: "Note",
17              column: 5
18            }
19          ]
20        }
21      ]
22    }
23  }
24}

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:

to top

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:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <data>
04     <data_providers>
05       <general_data_providers>
06         <data_provider data_set="dataSet1" id="s1">
07           <fields>
08             <field type="DateTime" custom_type_name="DateTimeStamp" column="4">
09               <date_time>
10                 <format><![CDATA[%yyyy%MM%dd]]></format>
11               </date_time>
12             </field>
13             <field type="DateTime" custom_type_name="UnixTimeStamp" column="5">
14               <date_time>
15                 <format><![CDATA[%u]]></format>
16               </date_time>
17             </field>
18           </fields>
19         </data_provider>
20       </general_data_providers>
21     </data_providers>
22   </data>
23 </stock>
01{
02  data: {
03    dataProviders: {
04      generalDataProviders: [
05        {
06          dataSet: "dataSet1",
07          id: "s1",
08          fields: [
09            {
10              type: "DateTime",
11              customTypeName: "DateTimeStamp",
12              column: 4,
13              dateTime: {
14                format: "%yyyy%MM%dd"
15              }
16            },
17            {
18              type: "DateTime",
19              customTypeName: "UnixTimeStamp",
20              column: 5,
21              dateTime: {
22                format: "%u"
23              }
24            }
25          ]
26        }
27      ]
28    }
29  }
30}

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:

to top

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:

XML/JSON Syntax
Plain code
03     <data_provider data_set="dataSet1" column="4" />
01{
03    {
04      dataSet: "dataSet1",
05      column: 4
06    }
07  ]
08}

To learn more about scroller data binding and configuration refer to:

to top

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:

to top