Data Sets

Overview

Data Set represents single CSV table within AnyChart Stock data model. Each data set links to the external file or contains CSV table within.

Data Set only contains data and does nothing with them, data sets are used by Data Providers, which are described in Data Provider Configuration article.

to top

Data Set Definition

Data set definition is done in <data_sets> node, please take a look at the sample XML:

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_sets>
05       <data_set id="dataSet1" source_mode="ExternalData" source_url="./data/msft_daily_short.csv" date_time_column="0">
06         <csv_settings ignore_first_row="true" rows_separator="\n" columns_separator="," />
07         <locale>
08           <date_time>
09             <format><![CDATA[%yyyy%MM%dd]]></format>
10           </date_time>
11         </locale>
12       </data_set>
13       <data_set id="dataSet2" source_mode="ExternalData" source_url="http://domain.com/provider/data.php" date_time_column="1">
14         <csv_settings ignore_first_row="true" rows_separator="\n" columns_separator="," />
15         <locale>
16           <date_time>
17             <format><![CDATA[%M/%d/%yyyy %h:%mm %tt]]></format>
18           </date_time>
19         </locale>
20       </data_set>
21       <data_set id="dataSet3" source_mode="InternalData" date_time_column="0">
22         <csv_data><![CDATA[1971-02-05;100;100;100;100
23 1971-02-08;100.84;100.84;100.84;100.84
24 1971-02-09;100.76;100.76;100.76;100.76
25 1971-02-10;100.69;100.69;100.69;100.69]]></csv_data>
26         <csv_settings ignore_first_row="false" rows_separator="\n" columns_separator=";" />
27         <locale>
28           <date_time>
29             <format><![CDATA[%yyyy-%MM-%dd]]></format>
30           </date_time>
31         </locale>
32       </data_set>
33     </data_sets>
34   </data>
35 </stock>
01{
02  data: {
03    dataSets: [
04      {
05        id: "dataSet1",
06        sourceMode: "ExternalData",
07        sourceUrl: "./data/msft_daily_short.csv",
08        dateTimeColumn: 0,
09        csvSettings: {
10          ignoreFirstRow: true,
11          rowsSeparator: "\n",
12          columnsSeparator: ","
13        },
14        locale: {
15          dateTime: {
16            format: "%yyyy%MM%dd"
17          }
18        }
19      },
20      {
21        id: "dataSet2",
22        sourceMode: "ExternalData",
23        sourceUrl: "http://domain.com/provider/data.php",
24        dateTimeColumn: 1,
25        csvSettings: {
26          ignoreFirstRow: true,
27          rowsSeparator: "\n",
28          columnsSeparator: ","
29        },
30        locale: {
31          dateTime: {
32            format: "%M/%d/%yyyy %h:%mm %tt"
33          }
34        }
35      },
36      {
37        id: "dataSet3",
38        sourceMode: "InternalData",
39        dateTimeColumn: 0,
40        csvData: "1971-02-05;100;100;100;100\r\n1971-02-08;100.84;100.84;100.84;100.84\r\n1971-02-09;100.76;100.76;100.76;100.76\r\n1971-02-10;100.69;100.69;100.69;100.69",
41        csvSettings: {
42          ignoreFirstRow: false,
43          rowsSeparator: "\n",
44          columnsSeparator: ";"
45        },
46        locale: {
47          dateTime: {
48            format: "%yyyy-%MM-%dd"
49          }
50        }
51      }
52    ]
53  }
54}

As you can see there are three data sets defined, two of them get data from external files (scripts) and one uses the table provided within config file. So, you can add as many different data sets as you need and decide what way of embedding data is more convenient to you.

To be specific, any data set definition must include:

The attributes that does this are:

Attributes Value Description
id String Unique Data Set identifier, which is later used by Data Providers.
source_mode Possible string values:
  "ExternalData"
  "InternalData"
Sets whether CSV data is built-in into XML or given in an external file.
source_url String
(any valid URL)
Sets the path to the file (or server side script) that provides data in CSV format.
Optional: you need it only when source_mode is set to ExternalData
date_time_column Number Sets zero-based index of the column with Date Time argument.

Full list of data set attributes and subnodes can be found in XML Reference, and below you will find more detailed explanation how to use and configure data sets with external and internal data.

to top

External CSV Data

Using external data is the preferred way to work with data in AnyChart Stock, because it allows you to use large data sets and separate data and configuration.

If you'd like to use external file or server side script as the source you need source_mode and source_url:

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_sets>
05       <data_set id="dataSet1" source_mode="ExternalData" source_url="./data/ixic_daily.csv" date_time_column="0" />
06     </data_sets>
07   </data>
08 </stock>
01{
02  data: {
03    dataSets: [
04      {
05        id: "dataSet1",
06        sourceMode: "ExternalData",
07        sourceUrl: "./data/ixic_daily.csv",
08        dateTimeColumn: 0
09      }
10    ]
11  }
12}

As you can see source_mode is set to "ExternalData" and source_url specifies path to the file or server side script.

Compression

When you have really large data sets and use external data sources, while the bandwidth is limited, you can use data compression to save the bandwidth and improve user experience. Please see more about this in:

to top

Cross Domain Policy

The value of source_url attribute is actually an URL that point to some file or script on the server and path can be either relative ("./../data.csv") or absolute ("http://www.mydomain.com/data/data.csv").

In some cases loading files may be restricted by Flash Player security policy, these cases are:

Different Domain

If page with the chart is located on one server (http://www.my-domain.com) and config file is located on another domain (http://www.another-domain.com) - you may want to set file:

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_sets>
05       <data_set id="dataSet1" source_mode="ExternalData" source_url="http://www.another-domain.com/data/ixic_daily.csv" date_time_column="0" />
06     </data_sets>
07   </data>
08 </stock>
01{
02  data: {
03    dataSets: [
04      {
05        id: "dataSet1",
06        sourceMode: "ExternalData",
07        sourceUrl: "http://www.another-domain.com/data/ixic_daily.csv",
08        dateTimeColumn: 0
09      }
10    ]
11  }
12}

and this wouldn't work unless you do one of the following things:

Secure Server (https://)

Secure servers may also restrict loading (especially in Internet Explorer), and you may need to:

See details in Security Error article.

to top

Allowing Caching

To avoid caching of source files by browser AnyChart Stock engine appends timestamp URL parameter to the external source URL, it is called XMLCallDate. For example, you write:

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_sets>
05       <data_set id="dataSet1" source_mode="ExternalData" source_url="http://www.mydomain.com/data/ixic_daily.csv" date_time_column="0" />
06     </data_sets>
07   </data>
08 </stock>
01{
02  data: {
03    dataSets: [
04      {
05        id: "dataSet1",
06        sourceMode: "ExternalData",
07        sourceUrl: "http://www.mydomain.com/data/ixic_daily.csv",
08        dateTimeColumn: 0
09      }
10    ]
11  }
12}

In this case AnyChart Stock engine makes request to:

http://www.mydomain.com/data/ixic_daily.csv?XMLCallDate=1278351919656

This parameter is a timestamp of the current time and is added to avoid config source caching. In some enthronements you may need to add handling of this parameter to your server-side script. Or, if you want to allow caching, you can do that by setting external_source_cache attribute to true:

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_sets>
05       <data_set id="dataSet1" source_mode="ExternalData" external_source_cache="true" source_url="http://www.mydomain.com/data/ixic_daily.csv" date_time_column="0" />
06     </data_sets>
07   </data>
08 </stock>
01{
02  data: {
03    dataSets: [
04      {
05        id: "dataSet1",
06        sourceMode: "ExternalData",
07        externalSourceCache: true,
08        sourceUrl: "http://www.mydomain.com/data/ixic_daily.csv",
09        dateTimeColumn: 0
10      }
11    ]
12  }
13}

to top

Internal CSV Data

Internal CSV data is a suitable option when you work with relatively small data sets and would like to keep everything (data and configuration) in one place.

If you'd like to use internal data as the source you need source_mode set to "InternalData" in <data_set> node and add a CSV data table into the <csv_data> subnode, 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_sets>
05       <data_set id="dataSet1" source_mode="InternalData" date_time_column="0">
06         <csv_data><![CDATA[Date,Open,High,Low,Close,Volume
07 19710205,100,100,100,100,0
08 19710208,100.84,100.84,100.84,100.84,0
09 19710209,100.76,100.76,100.76,100.76,0
10 19710210,100.69,100.69,100.69,100.69,0
11 19710211,101.45,101.45,101.45,101.45,0
12 19710212,102.05,102.05,102.05,102.05,0
13 19710216,102.19,102.19,102.19,102.19,0
14 19710217,101.74,101.74,101.74,101.74,0
15 19710218,101.42,101.42,101.42,101.42,0]]></csv_data>
16       </data_set>
17     </data_sets>
18   </data>
19 </stock>
01{
02  data: {
03    dataSets: [
04      {
05        id: "dataSet1",
06        sourceMode: "InternalData",
07        dateTimeColumn: 0,
08        csvData: "Date,Open,High,Low,Close,Volume\r\n19710205,100,100,100,100,0\r\n19710208,100.84,100.84,100.84,100.84,0\r\n19710209,100.76,100.76,100.76,100.76,0\r\n19710210,100.69,100.69,100.69,100.69,0\r\n19710211,101.45,101.45,101.45,101.45,0\r\n19710212,102.05,102.05,102.05,102.05,0\r\n19710216,102.19,102.19,102.19,102.19,0\r\n19710217,101.74,101.74,101.74,101.74,0\r\n19710218,101.42,101.42,101.42,101.42,0"
09      }
10    ]
11  }
12}

All other settings are similar for data sets with external and internal data, please see how you should define CSV settings and Date Time locale in the sections shown below.

 

to top

CSV Settings

To describe CSV formatting options you should use <csv_settings> node that tells the component how to parse data. See sample XML syntax of such settings:

XML/JSON Syntax
Plain code
01{
02  csvSettings: {
03    ignoreFirstRow: true,
04    rowsSeparator: "\n",
05    columnsSeparator: ","
06  }
07}

As you can see there are three attributes set in <csv_settings>:

Attributes Description
ignore_first_row Sets are there any data in the first row, or it contains headers it can be "true" or "false".
rows_separator Sets the symbol that separates rows. To set end of line as rows separator "\n" is used .
columns_separator Sets column separator symbol.
ignore_trailing_spaces Sets whether the internal CSV parser should trim spacing characters from the both sides of parsed values.

Detailed explanation of CSV data table requirements can be found in:

to top

Date Time Column and Locale Settings

Every data set should contain a column with Date Time data and information about the way this column is formatted. For example date time column is the first one, so date_time_column attribute is set to zero.

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_sets>
05       <data_set id="dataSet1" source_mode="ExternalData" source_url="./data/ixic_daily.csv" date_time_column="0">
06         <csv_settings ignore_first_row="true" rows_separator="\n" columns_separator="," />
07         <locale>
08           <date_time>
09             <format><![CDATA[%yyyy%MM%dd]]></format>
10           </date_time>
11         </locale>
12       </data_set>
13     </data_sets>
14   </data>
15 </stock>
01{
02  data: {
03    dataSets: [
04      {
05        id: "dataSet1",
06        sourceMode: "ExternalData",
07        sourceUrl: "./data/ixic_daily.csv",
08        dateTimeColumn: 0,
09        csvSettings: {
10          ignoreFirstRow: true,
11          rowsSeparator: "\n",
12          columnsSeparator: ","
13        },
14        locale: {
15          dateTime: {
16            format: "%yyyy%MM%dd"
17          }
18        }
19      }
20    ]
21  }
22}

To define Date Time format for argument locale subnode is used. In the sample above locale is set to understand data in the following format: four symbols for year, next two are month and the last two - day. (values that looks like: 19710205, 19710208, 19710209 and so long).

So, the tokens mean:

AnyChart Stock Component supports a lot of tokens, so you can use almost any date time format. Full list of the tokens, sample and description can be found in

to top

Server Side Scripts to generate dynamic data

In all samples in this documentation we use static CSV files as data sources, but you should understand that you can use the URL of some server-side script as data source, all you need to make sure of is the fact that this script returns CSV table according to the rules set in configuration. You can also append some parameters to the source URL to make it return some selected subset of the data.

This option is demonstrated in the following online sample:

Online HTML/JavaScript Sample

to top

How to use data from data sets

The data from Data Sets are used by Data Providers, please see the article below to learn how to do that:

to top