Input Data Settings

Overview

AnyChart Stock gets data in the CSV format, so configuring the CSV settings properly is something you must carefully observe and double-check.

The component's engine cannot figure out which exactly format is used in the CSV table, so it is your responsibility to make the CSV table settings and timestamp format in a way that the component would be able to parse the input data.

A CSV table can come from a third-party server-side script, Web-Service or file, and sometimes developer cannot modify the format of that table (or that may be a challenging task). For such cases, AnyChart Stock has a lot of options that enable it to use CSV tables with just about any possible formatting.

As you should already know from the AnyChart Data Model, a CSV table is wrapped with a Data Set, which knows where the table comes from. When specifying the data source value in the Data Set, you should also specify how the source table is formatted.

There are two major nodes that define source CSV table format:

Here is a sample XML that shows two Data Sets with different locale and CSV settings:

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_set id="dataSet2" source_mode="ExternalData" source_url="./data/hourly_data.csv" date_time_column="0">
14         <csv_settings ignore_first_row="false" rows_separator="\n" columns_separator=";" />
15         <locale>
16           <date_time>
17             <format><![CDATA[%yyyy-%MM-%dd %h]]></format>
18           </date_time>
19         </locale>
20       </data_set>
21     </data_sets>
22   </data>
23 </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        id: "dataSet2",
22        sourceMode: "ExternalData",
23        sourceUrl: "./data/hourly_data.csv",
24        dateTimeColumn: 0,
25        csvSettings: {
26          ignoreFirstRow: false,
27          rowsSeparator: "\n",
28          columnsSeparator: ";"
29        },
30        locale: {
31          dateTime: {
32            format: "%yyyy-%MM-%dd %h"
33          }
34        }
35      }
36    ]
37  }
38}

to top

CSV Settings and CSV Table Requirements

The CSV parser in AnyChart Stock supports Comma Separated Values format specifications, and some of the CSV parameters are configurable.

If you need to learn more about the CSV format, this article is a good starting point:

CSV Table Requirements

First of all, the nature of the component requires the CSV table to have at least two columns: one with timestamps and the other (others) with values.

General requirements are:

CSV Parser Settings

As it has been said already, some CSV table settings can be customized; if the CSV tables you use don't fit the default settings, you can alter the parser settings, so that it could read the data properly.

The <csv_settings> node has the following attributes:

Attribute Default Description
ignore_first_row (!) "false" Sets whether the parser should ignore the first row of data. It may be useful when the first row contains column descriptions. Can be true or false.
rows_separator (!) "\r\n" Sets the string that separates rows in the CSV data set. The most common separators are new line (LF) - "\n", new line and carriage return (CR LF) - "\r\n" and carriage return (CR) "\r".

The component also recognizes these special separator characters: "\n", "\r" and "\t". To use the backslash "\" as a part of the separator, escape it by typing the double backslash: "\\". Other characters after the "\" character are used as they are, and the "\" character is replaced and ignored.
columns_separator (!) ","

Sets a string that separates columns in a CSV data set. The most common separators are ";" and ",".

The component also recognizes these special separator characters: "\n", "\r" and "\t". To use the backslash "\" as a part of the separator, escape it by typing the double backslash: "\\". Other characters after the "\" character are used as they are, and the "\" character is replaced and ignored.

ignore_trailing_spaces "false" Sets whether the CSV parser should trim the space characters from both sides of the parsed values. Can be true or false.

Note: We have marked the three out of four attributes with (!) because misunderstanding and misusing those can become a real pain in the neck and turn the process of creating a simple chart into hell. Please consider the following recommendations:

1) Check the first row of the CSV table - does it contain column headers?

2) If the columns are separated with a character other than comma - define it using the columns_separator attribute; for example, <csv_settings columns_separator="\t">.

3) If the rows are separated with a character other than carriage return and line feed ("\r\n") - define it using the rows_separator attribute; for example, <csv_settings rows_separator=";"/>.

The sample XML below shows how the CSV settings can be altered:

XML/JSON Syntax
Plain code
01 <data_set id="ds1" source_mode="InternalData" date_time_column="0">
02   <locale>
03     <date_time>
04       <format><![CDATA[%yyyy-%MM-%dd]]></format>
05     </date_time>
06   </locale>
08   <csv_data><![CDATA[Date;Open;High;Low;Close;Volume
09 1971-02-05;100;100;100;100;0
10 1971-02-08;100.84;100.84;100.84;100.84;0
11 1971-02-09;100.76;100.76;100.76;100.76;0
12 1971-02-10;100.69;100.69;100.69;100.69;0
13 1971-02-11;101.45;101.45;101.45;101.45;0
14 1971-02-12;102.05;102.05;102.05;102.05;0
15 1971-02-16;102.19;102.19;102.19;102.19;0
16 1971-02-17;101.74;101.74;101.74;101.74;0
17 1971-02-18;101.42;101.42;101.42;101.42;0]]></csv_data>
18 </data_set>
01{
02  id: "ds1",
03  sourceMode: "InternalData",
04  dateTimeColumn: 0,
05  locale: {
06    dateTime: {
07      format: "%yyyy-%MM-%dd"
08    }
09  },
10  csvSettings: {
11    ignoreFirstRow: true,
12    columnsSeparator: ";",
13    rowsSeparator: "\r\n"
14  },
15  csvData: "Date;Open;High;Low;Close;Volume\r\n1971-02-05;100;100;100;100;0\r\n1971-02-08;100.84;100.84;100.84;100.84;0\r\n1971-02-09;100.76;100.76;100.76;100.76;0\r\n1971-02-10;100.69;100.69;100.69;100.69;0\r\n1971-02-11;101.45;101.45;101.45;101.45;0\r\n1971-02-12;102.05;102.05;102.05;102.05;0\r\n1971-02-16;102.19;102.19;102.19;102.19;0\r\n1971-02-17;101.74;101.74;101.74;101.74;0\r\n1971-02-18;101.42;101.42;101.42;101.42;0"
16}

The live sample below uses several data sets that use CSV tables formatted different ways:

Live Sample:  Input Data - CSV Parsing Settings

to top

Using Non-Latin and Special Symbols

When you use non-latin symbols in CSV files you need to make sure your file (or script output) is UTF-8 encoded.

If you are using internal data sets you should not only make sure XML file is UTF-8 encoded, but also:

If you would not follow the rules listed above - in some browser CSV table may be parsed incorrectly. The screen shot below shows the sample internal data set formatted properly:

to top

Timestamps

AnyChart Stock can accept and visualize date and time data at up to a millisecond precision. Every data set must contain the timestamp column, and its date-time format must be specified.

Timestamp format

The timestamp format string is set in the <format> node. This format string uses special tokens. The sample XML below demonstrates it. For better understanding, we will use an internal CSV table:

XML/JSON Syntax
Plain code
01 <data_set id="ds1" source_mode="InternalData" date_time_column="0">
02   <locale>
03     <date_time>
04       <format><![CDATA[%yyyy-%MM-%dd]]></format>
05     </date_time>
06   </locale>
07   <csv_data><![CDATA[Date,Value
08 1971-02-05,100.00
09 1971-02-08,100.84
10 1971-02-09,100.76]]></csv_data>
11 </data_set>
01{
02  id: "ds1",
03  sourceMode: "InternalData",
04  dateTimeColumn: 0,
05  locale: {
06    dateTime: {
07      format: "%yyyy-%MM-%dd"
08    }
09  },
10  csvData: "Date,Value\r\n1971-02-05,100.00\r\n1971-02-08,100.84\r\n1971-02-09,100.76"
11}

As you can see here, the CSV table contains daily data with timestamps that appear as: 1971-02-05, 1971-10-23, etc. Here, years are represented by four digits, months and days - by two with leading zeros, and all the units are separated with the "-" character.

To help AnyChart Stock properly interpret this timestamp, we will specify the following input format string: "%yyyy-%MM-%dd", where the tokens have the following meanings:

And the "-" character, used as the separator, is also included in the proper positions of the format string.

There are no restrictions on using timestamp formats - you can use any; just make sure to specify the formatting string properly and that all the values in the timestamp column satisfy that string.

Take a look at the table below; it highlights the case which should never happen with the timestamp column:

Correct Wrong!
1990-03-26
1990-04-02
1990-04-09
1990-04-16
1990-04-23
1990-03-26
1990-04-02
1990/4/9
1990-04-16
1990-04-23

As we have already said, you can use any format - with any separators, prefixes and suffixes. The table below demonstrates several different formatting strings, which use the same tokens %yyyy, %MM and %dd arranged in different ways:

Description Timestamps Timestamp format string
Year, month, day with the "-" separator. 1990-03-26
1990-04-02
1990-04-09
1990-04-16
1990-04-23
"%yyyy-%MM-%dd"
Year, month, day with leading zeros can be used without separators. 19900326
19900402
19900409
19900416
19900423
"%yyyy%MM%dd"
Month, day, year with the "/" separator. 03/26/1990
04/02/1990
04/09/1990
04/16/1990
04/23/1990
"%MM/%dd/%yyyy"

Year, month, day with prefixes and the comma (",") separator.

Note: As stated in the requirements, if a timestamp contains a comma, and the column separator is comma (default) - the timestamp should be typed in double quotes.

"Y:1990,M:03,D:26"
"Y:1990,M:04,D:02"
"Y:1990,M:04,D:09"
"Y:1990,M:04,D:16"
"Y:1990,M:04,D:23"
"Y:%yyyy,M:%MM,D:%dd"

This table has demonstrated an example of basic formatting; depending on the task, you can use any format and apply the hour, minute, second or milliseconds precision.

The section below shows all the tokens that can be used in a timestamp formatting string.

to top

Tokens for Date-Time Format

AnyChart Stock's timestamp formatting string can be divided in two categories: complex and standard:

The table below lists all the available tokens that can be used in a formatting string that parses input timestamp. The Examples column shows sample timestamps and the formatting strings used for parsing them:

Token Description Examples
%u

Expects the number of Seconds elapsed since midnight of January 1, 1970.

Should follow the Unix Timestamp format.

When using this token, no other tokens can be used in the mask, and the timestamp can contain only one numerical value.

Timestamp: "1269675274"

Mask: "%u"

%T

Expects the number of Milliseconds since midnight of January 1, 1970

When using this token, no other tokens can be used in the mask, and the timestamp can contain only one numerical value.

Timestamp: "1269675350168"

Mask: "%T"

%d

Expects day of month as a number from 1 through 31.

Single-digit days must be formatted without a leading zero.

Note: Must be followed by a non-digit character - read more...

Timestamp: "6/9/2009"

Mask: "%M/%d/%yyyy"

%dd Expects day of month as a number from 01 through 31.

Single-digit days must be formatted with a leading zero.

Timestamp: "06/09/2009"

Mask: "%MM/%dd/%yyyy"

%ddd

Expects short weekday name.

The name must match the locale settings and doesn't affect the result - read more...

Timestamp: "06-Sep-2009"

Mask: "%MM-%ddd-%yyyy"

%dddd

Expects full weekday name.

The name should match the locale settings and doesn't affect the result - read more...

Timestamp: "06-September-2009"

Mask: "%MM-%dddd-%yyyy"

%M

Expects month as a number from 1 through 12.

Single-digit months must be formatted without a leading zero.

Note: Must be followed by a non-digit character - read more...

Timestamp: "6/23/2009"

Mask: "%M/%d/%yyyy"

%MM Expects month as a number from 01 through 12.

Single-digit months must be formatted with a leading zero.

Timestamp: "06/09/2009"

Mask: "%MM/%dd/%yyyy"

%MMM Expects abbreviated month name.

The name should match the locale settings - read more...

Timestamp: 25 Feb, 2009"

Mask: "%d %MMM, %yyyy"

%MMMM Expects full month name.

The name should match the locale settings - read more...

Timestamp: "25 February, 2009"

Mask: "%d %MMMM, %yyyy"

%yy Expects year as a two-digit number.

If the year has more than two digits, only the two lower-order digits will appear. If a two-digit year has fewer than two value digits, the number must be padded with leading zeros until obtaining two digits.

Timestamp: "2/25/09"

Mask: "%M/%d/%yy"

%yyyy Expects year as a four-digit number.

Timestamp: "2/25/2009"

Mask: "%M/%d/%yyyy"

%h

Expects hour as a number from 1 through 12.

The hour is represented by the 12-hour clock, which counts whole hours since midnight or noon. A particular hour after midnight is indistinguishable from the same hour after noon. The hour is not rounded, and single-digit hours are formatted without a leading zero. For example, given the time of 4:12 in the morning or afternoon, this custom format specifier expects "4".

Note: Must be followed by a non-digit character - read more...

Timestamp: "2/25/2009 3:15 PM"

Mask: "%M/%d/%yyyy %h:%mm %tt"

%hh Expects hour as a number from 01 through 12.

The hour is represented by the 12-hour clock that counts whole hours since midnight or noon. A particular hour after midnight is indistinguishable from the same hour after noon. The hour is not rounded, and single-digit hours are formatted with a leading zero. For example, given the time of 4:12 in the morning or afternoon, this format specifier expects "04".

Timestamp: "2/25/2009 03:15 PM"

Mask: "%M/%d/%yyyy %hh:%mm %tt"

%H

Expects hour as a number from 0 through 23.

The hour is represented by the zero-based 24-hour clock that counts whole hours since midnight. Single-digit hours must be formatted without a leading zero.

Note: Must be followed by a non-digit character - read more...

Timestamp: "2/25/2009 17:15"

Mask: "%M/%d/%yyyy %H:%mm %tt"

%HH Expects hour as a number from 00 through 23.

The hour is represented by the zero-based 24-hour clock that counts whole hours since midnight. Single-digit hours must be formatted with a leading zero.

Timestamp: "2/25/2009 17:15"

Mask: "%M/%d/%yyyy %HH:%mm %tt"

%m

Expects minute as a number from 0 through 59.

The value represents the number of whole minutes passed since the last hour. Single-digit minute s must be formatted without a leading zero.

Note: Must be followed by a non-digit character - read more...

Timestamp: "2/25/2009 3:15 PM"

Mask: "%M/%d/%yyyy %h:%m %tt"

%mm Expects minute as a number from 00 through 59.

The value represents the number of whole minutes passed since the last hour. Single-digit minutes must be formatted with a leading zero.

Timestamp: "2/25/2009 3:15 PM"

Mask: "%M/%d/%yyyy %h:%mm %tt"

%s

Expects seconds as a number from 0 through 59.

The value represents the number of whole seconds passed since the last minute. Single-digit seconds must be formatted without a leading zero.

Note: Must be followed by a non-digit character - read more...

Timestamp: "2/25/2009 17:15:23"

Mask: "%M/%d/%yyyy %H:%mm:%s"

%ss Expects seconds as a number from 00 through 59.

The value represents the number of whole seconds passed since the last minute. Single-digit seconds must be formatted with a leading zero.

Timestamp: "2/25/2009 17:15:03"

Mask: "%M/%d/%yyyy %H:%mm:%ss"

%f Expects the most significant digit of the seconds fraction; i.e., it expects the tenths of a second in the date and time value.

Timestamp: "2/25/2009 17:15:23.3"

Mask: "%M/%d/%yyyy %H:%mm:%ss.%f"

%ff Expects two most significant digits of the seconds fraction; i.e., it expects the hundredths of a second in the date and time value.

Timestamp: "2/25/2009 17:15:23.55"

Mask: "%M/%d/%yyyy %H:%mm:%ss.%ff"

%fff Expects three most significant digits of the seconds fraction; i.e., it expects the milliseconds in the date and time value.

Timestamp: 2/25/2009 17:15:23.076

Mask: "%M/%d/%yyyy %H:%mm:%ss.%fff"

%t Expects the first character of the AM/PM designator.

Designators should match the locale settings: read more...

Timestamp: "2/25/2009 3:15 P"

Mask: "%M/%d/%yyyy %h:%mm %t"

%tt Expects the entire AM/PM designator.

Designators should match the locale settings: read more...

Timestamp: "2/25/2009 3:15 PM"

Mask: "%M/%d/%yyyy %h:%mm %tt"


Note: Tokens without leading zeros

The %M, %d, %h, %m and %s tokens must always be followed by a non-digit character; e.g., "/", ":", " ", or must be at the end of the string. Failing to follow this rule may cause incorrect parsing of the date.

to top

Month and Weekday Name Localization

Month Names

If you need to use timestamps with month names instead of month numbers, and the names are not specified in English - you need to define what names are to be used.

To use the textual representation of months names, you need the %MMM or %MMMM token; the first one expects abbreviated month names (e.g. Jan, Feb, etc.), and the second one - full names (e.g. January, February, etc.)

To change month names from English to any other, use the <names> node - for %MMMM, and the <short_names> node - for %MMM. In these nodes, list the new month names from January through December.

This sample XML shows how to change the full and abbreviated names to Czech:

XML/JSON Syntax
Plain code
01 <data_set>
02   <locale>
03     <date_time>
04       <months>
05         <names><![CDATA[leden,únor,březen,duben,květen,červen,červenec,srpen,září,říjen,listopad,prosinec]]></names>
06         <short_names><![CDATA[I,II,III,IV,V,VI,VII,VIII,IX,X,XI,XII]]></short_names>
07       </months>
08     </date_time>
09   </locale>
10 </data_set>
01{
02  locale: {
03    dateTime: {
04      months: {
05        names: "leden,únor,březen,duben,květen,červen,červenec,srpen,září,říjen,listopad,prosinec",
06        shortNames: "I,II,III,IV,V,VI,VII,VIII,IX,X,XI,XII"
07      }
08    }
09  }
10}

Once these names are set, the parser is able to properly interpret timestamps like: "12-II-2009" or "23-duben-2009"

The advanced explanation accompanied with samples can be found in:

Weekday Names

To use the full or short weekday names, you need the %dddd or %ddd tokens. If these names come in a language other than English, they should be specified in the <names> and <short_names> subnodes of the <week_days> node. The weekday names must be listed from Sunday through Saturday.

The sample XML below shows how to make the parser understand weekday names in Czech:

XML/JSON Syntax
Plain code
01 <data_set>
02   <locale>
03     <date_time>
04       <week_days>
05         <names><![CDATA[neděle,pondělí,úterý,středa,čtvrtek,pátek,sobota]]></names>
06         <short_names><![CDATA[ne,po,út,st,čt,pá,so]]></short_names>
07       </week_days>
08     </date_time>
09   </locale>
10 </data_set>
01{
02  locale: {
03    dateTime: {
04      weekDays: {
05        names: "neděle,pondělí,úterý,středa,čtvrtek,pátek,sobota",
06        shortNames: "ne,po,út,st,čt,pá,so"
07      }
08    }
09  }
10}

The advanced information accompanied with samples can be found in:

 

to top

AM/PM Designators

Be default, the %tt token expects the "AM" or "PM" string, and %t - "A" or "P". If you use timestamps in the 12-hour format and use other AM/PM designators, you need to define new designators.

To change the full designators, use the am_string and pm_string attributes for the %tt node, and to change the short designators use the short_am_string and short_pm_string attributes (used in %t) of the <time> node.

Here is a sample XML syntax that demonstrates the use of timestamps with lower-case designators with dots: "5:15 p.m.", "5:15 a.m.":

XML/JSON Syntax
Plain code
01 <data_set>
02   <locale>
03     <date_time>
04       <time am_string="a.m." pm_string="p.m." short_am_string="a" short_pm_string="p" />
05     </date_time>
06   </locale>
07 </data_set>
01{
02  locale: {
03    dateTime: {
04      time: {
05        amString: "a.m.",
06        pmString: "p.m.",
07        shortAmString: "a",
08        shortPmString: "p"
09      }
10    }
11  }
12}

More samples on using AM/PM designators, accompanied with detailed descriptions, can be found in:

to top

Formatting Samples

This section shows and explains samples of most popular formats. These formats are divided in several section, in each you will find sample format mask, explanation and live samples.

Timestamps with Date

To work with timestamps where day, month and year are shown as numbers you can use the following:

The table below demonstrates a few samples of formatting mask with these tokens:

Description Timestamps Timestamp mask format
Month and day without leading zero: month, day and year separated with "/". 1/6/2009
2/27/2009
10/14/2009
12/9/2009
"%M/%d/%yyyy"
Month and day with leading zero: month, day and year separated with "/". 01/06/2009
02/27/2009
10/14/2009
12/09/2009
"%MM/%dd/%yyyy"
Month and day without leading zero: month, day and year separated with "." 6.1.2009
27.2.2009
14.10.2009
9.12.2009
"%d.%M.%yyyy"
Month and day with leading zero: month, day and year separated with "." 06.01.2009
27.02.2009
14.10.2009
09.12.2009
"%dd.%MM.%yyyy"
Month and day with leading zero: year, month and day separated with "-" 2009-01-06
2009-02-27
2009-10-14
2009-12-09
"%yyyy-%MM-%dd"
Month and day with leading zero and year as two numbers, separated with "/" 01/06/09
02/27/09
10/14/09
12/09/09
"%MM/%dd/%yy"
Year, month and day with leading zeros without any separators. 20090106
20090227
20091014
20091209
"%yyyy%MM%dd"

The live sample below shows the same table in three formats with different timestamps: "%M/%d/%yyyy", "%dd.%MM.%yyyy" and "%yyyy-%MM-%dd":

Live Sample:  Input Data - Parsing Different Timestamps

to top

Timestamps with Month Names (e.g. 2009-Jan-17)

To use month names instead of month numbers - i.e. timestamps like "5 Jan, 2008" or "5 January, 2008" - your mask formatting string must include the %MMM or %MMMM token.

When these tokens are included in the mask, parser checks the full or abbreviated month names and converts those to the numbers.

Note: Either full or abbreviated month names must strictly match the default or locale-defined values. Using undefined names can result in parsing failure.

Changing short and full months names is described in:

The table below demonstrates a few samples of formatting mask with short and full month names:

Description Timestamps Timestamp mask format
Dates with short month names 17 Jan, 2009
17 Feb, 2009
17 Mar, 2009
17 Apr, 2009
17 May, 2009
17 Jun, 2009
17 Jul, 2009
17 Aug, 2009
17 Sep, 2009
17 Oct, 2009
17 Nov, 2009
17 Dec, 2009
"%dd %MMM, %yyyy"
Dates with full month names 17 January, 2009
17 February, 2009
17 March, 2009
17 April, 2009
17 May, 2009
17 June, 2009
17 July, 2009
17 August, 2009
17 September, 2009
17 October, 2009
17 November, 2009
17 December, 2009
"%dd %MMMM, %yyyy"
Dates with short month names + Time 17 Jan, 2009 4:34:12 AM
17 Feb, 2009 4:34:12 AM
17 Mar, 2009 4:34:12 AM
17 Apr, 2009 4:34:12 AM
17 May, 2009 4:34:12 AM
17 Jun, 2009 4:34:12 AM
17 Jul, 2009 4:34:12 AM
17 Aug, 2009 4:34:12 AM
17 Sep, 2009 4:34:12 AM
17 Oct, 2009 4:34:12 AM
17 Nov, 2009 4:34:12 AM
17 Dec, 2009 4:34:12 AM
"%dd %MMM, %yyyy %h:%mm:%ss %tt "
Dates with full month names + Time 17 January, 2009 4:34:12 AM
17 February, 2009 4:34:12 AM
17 March, 2009 4:34:12 AM
17 April, 2009 4:34:12 AM
17 May, 2009 4:34:12 AM
17 June, 2009 4:34:12 AM
17 July, 2009 4:34:12 AM
17 August, 2009 4:34:12 AM
17 September, 2009 4:34:12 AM
17 October, 2009 4:34:12 AM
17 November, 2009 4:34:12 AM
17 December, 2009 4:34:12 AM
"%dd %MMMM, %yyyy %h:%mm:%ss %tt "

Here is a live sample with a data set that uses the "%d-%MMMM-%yyyy" formatting mask. The CSV table built into the XML is used for demonstration purposes:

Live Sample:  Input Data Sample - Parsing Timestamps with Month Names

to top

Timestamps with Weekday Names (e.g. Monday, 01/27/2009)

When you need to use a timestamp with a weekday name (which is not recommended though), like "Sunday, 5/15/2009", you can use the %ddd or %dddd tokens. The first one expects the abbreviated, and the second one - full weekday name. Please note that weekday name doesn't affect the date calculation at all.

Please use these tokens only when you have to use timestamps with weekday names; if you can create timestamps without the names - do that, because that improves the performance greatly.

Note: By default, the parser understands only English weekday names, if you need to parse weekday names in other languages, you need to redefine those in the locale settings.

To learn more about localizing weekday names, please see:

The table below demonstrates a few variants with weekday names in the formatting mask:

Description Timestamps Timestamp mask format
Shortened weekday at the beginning. Mon, 29 March 2010
Tue, 30 March 2010
Wed, 31 March 2010
Thu, 1 April 2010
Fri, 2 April 2010
Sat, 3 April 2010
Sun, 4 April 2010
"%ddd, %d %MMMM %yyyy"
Full weekday at the beginning. Monday, 29 March 2010
Tuesday, 30 March 2010
Wednesday, 31 March 2010
Thursday, 1 April 2010
Friday, 2 April 2010
Saturday, 3 April 2010
Sunday, 4 April 2010
"%dddd, %d %MMMM %yyyy"
Weekday as part of timestamp. 29 March - Monday, 2010
30 March - Tuesday, 2010
31 March - Wednesday, 2010
1 April - Thursday, 2010
2 April - Friday, 2010
3 April - Saturday, 2010
4 April - Sunday, 2010
"%d %MMMM - %dddd, %yyyy"

This live sample demonstrates data set with timestamps that contain weekday names:

Live Sample:  Input Data - Parsing Timestamps with Days of Week

to top

12-hour time format (e.g. 5:35:30 PM)

The 12-hour clock is a time conversion convention, in which the 24 hours of the day are divided into two periods called ante meridiem (a.m., Latin: "before mid day" English: "before noon") and post meridiem (p.m., Latin: "after mid day" English: "after noon"). Each period consists of 12 hours, numbered as 12 (acting as zero), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, and 11.

A good starting point to learn more about this format is:

These are tokens that can be used for parsing timestamps in the 12-hour format:

Note: If you use the 12-hour time format, you must use the %t or %tt tokens in the format string and the AM/PM designators in timestamps. If the designator format is different from the default, you can change it. Changing designators is described in:

The table below demonstrates different variations of formatting masks along with sample timestamps:

Description Timestamps Timestamp mask format
Hours 12/6/2009 3 AM
12/6/2009 5 PM
12/6/2009 11 PM
12/6/2009 6 AM
"%M/%d/%yyyy %h %tt"
Hours + Minutes 12/6/2009 3:15 AM
12/6/2009 5:32 PM
12/6/2009 11:10 PM
12/6/2009 6:45 AM
"%M/%d/%yyyy %h:%mm %tt"
Hours + Minutes + Seconds 12/6/2009 3:15:10 AM
12/6/2009 5:32:27 PM
12/6/2009 11:10:18 PM
12/6/2009 6:45:14 AM
"%M/%d/%yyyy %h:%mm:%ss %tt"
Hours(with leading zero) 12/6/2009 03 AM
12/6/2009 05 PM
12/6/2009 11 PM
12/6/2009 06 AM
"%M/%d/%yyyy %hh %tt"
Hours(with leading zero) + Minutes 12/6/2009 03:15 AM
12/6/2009 05:32 PM
12/6/2009 11:10 PM
12/6/2009 06:45 AM
"%M/%d/%yyyy %hh:%mm %tt"
Hours(with leading zero) + Minutes + Seconds 12/6/2009 03:15:10 AM
12/6/2009 05:32:27 PM
12/6/2009 11:10:18 PM
12/6/2009 06:45:14 AM
"%M/%d/%yyyy %hh:%mm:%ss %tt"

If your data set shows data within a day, you can use the Base Date method to make the data set smaller. Learn more about that in:

Here is a live sample with a data set that uses the "%M/%d/%yyyy %h:%mm:%ss %tt" formatting. The data set built into the XML is used for demonstration purposes:

Live Sample:  Input Data Sample - Parsing Timestamps with 12 Hours Format

to top

24-hour time format (e.g. 17:35:30)

The 24-hour clock is a convention of time keeping, in which a day runs from midnight to midnight and is divided into 24 hours, indicated by the hours passed since midnight, from 0 to 23. This time notation system is the world's most commonly used one.

You can learn more about the 24-hour format in:

The following tokens are used for the 24-hour format:

The table below demonstrates a few variations of formatting masks along with 24-hour format timestamps:

Description Timestamps Timestamp mask format
Hours 23.12.2009 0
23.12.2009 17
23.12.2009 23
23.12.2009 4
"%MM.%dd.%yyyy %H"
Hours + Minutes 23.12.2009 15:23
23.12.2009 17:32
23.12.2009 11:10
23.12.2009 6:45
"%MM.%dd.%yyyy %H:%mm"
Hours + Minutes + Seconds 23.12.2009 3:15:10
23.12.2009 17:32:27
23.12.2009 11:10:18
23.12.2009 6:45:14
"%MM.%dd.%yyyy %H:%mm:%ss"
Hours(with leading zero) 23.12.2009 00
23.12.2009 17
23.12.2009 23
23.12.2009 04
"%MM.%dd.%yyyy %HH"
Hours(with leading zero) + Minutes 23.12.2009 15:23
23.12.2009 17:32
23.12.2009 11:10
23.12.2009 06:45
"%MM.%dd.%yyyy %HH:%mm"
Hours(with leading zero) + Minutes + Seconds 23.12.2009 03:15:10
23.12.2009 17:32:27
23.12.2009 11:10:18
23.12.2009 06:45:14
"%MM.%dd.%yyyy %HH:%mm:%ss"

The live sample below shows a data set with the "%dd.%MM.%yyyy %HH:%mm:%ss" formatting mask. The data set built into the XML is used for demonstration purposes:

Live Sample:  Input Data Sample - Parsing Timestamps with 24 Hours Format

to top

Unix Timestamps

Unix timestamp is a way of tracking time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970. Therefore, unix timestamp is merely the number of seconds between a particular date and the Unix Epoch. This is very useful to computer systems for tracking and sorting dated data in dynamic and distributed applications, both online and client-side.

A good starting point to learn more about Unix Timestamp is:

The table below shows what timestamps of this format look like:

Timestamps Timestamp format string
1269680933
1269681053
1269681353
1269681653
1269681953
%u

Here is a sample XML for making the parser understand timestamps in this format:

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         <locale>
07           <date_time>
08             <format><![CDATA[%u]]></format>
09           </date_time>
10         </locale>
11         <csv_settings ignore_first_row="false" rows_separator="\n" columns_separator="," />
12         <csv_data><![CDATA[915570000,24.4
13 915656400,25.73
14 916002000,25.89
15 916088400,26.71
16 916174800,25.95
17 916261200,25.24
18 916347600,25
19 916434000,25.63
20 916693200,25.89]]></csv_data>
21       </data_set>
22     </data_sets>
23   </data>
24 </stock>
01{
02  data: {
03    dataSets: [
04      {
05        id: "dataSet1",
06        sourceMode: "InternalData",
07        dateTimeColumn: 0,
08        locale: {
09          dateTime: {
10            format: "%u"
11          }
12        },
13        csvSettings: {
14          ignoreFirstRow: false,
15          rowsSeparator: "\n",
16          columnsSeparator: ","
17        },
18        csvData: "915570000,24.4\r\n915656400,25.73\r\n916002000,25.89\r\n916088400,26.71\r\n916174800,25.95\r\n916261200,25.24\r\n916347600,25\r\n916434000,25.63\r\n916693200,25.89"
19      }
20    ]
21  }
22}

The live sample below shows a chart with the timestamps in the CSV table are Unix timestamps. For demonstration purposes, we will use the CSV table built into the XML:

Live Sample:  Input Data Sample - Parsing Timestamps with Unix Time

to top

Timestamps in Milliseconds

You have two ways to use timestamps at a millisecond precision:

The table below demonstrates different variants of timestamps and masks with milliseconds:

Description Timestamps Timestamp mask format
Milliseconds since midnight January 1, 1970 1269689056645
1269689056768
1269689056891
1269689057014

"%T"
Tens of milliseconds 23.12.2009 23:15:10.2
23.12.2009 23:15:10.5
23.12.2009 23:15:10.2
23.12.2009 23:15:10.9
"%MM.%dd.%yyyy %H:%mm:%ss.%f"
Hundreds of milliseconds 23.12.2009 23:15:10.21
23.12.2009 23:15:10.58
23.12.2009 23:15:10.04
23.12.2009 23:15:10.95
"%MM.%dd.%yyyy %H:%mm:%ss.%ff"
Milliseconds 23.12.2009 23:15:10.218
23.12.2009 23:15:10.581
23.12.2009 23:15:10.047
23.12.2009 23:15:10.959
"%MM.%dd.%yyyy %H:%mm:%ss.%fff"

If you use complex timestamps like "23.12.2009 23:15:10.047", you can make them shorter using the Base Date method. This method is described in:

The live sample below demonstrates using several CSV tables with different timestamps:

Live Sample:  Input Data Sample - Parsing Timestamps in Milliseconds

to top

Using Base Date to Shorten Timestamps

To explain what Base Date is, and how you can make use of it, we will give you a little explanation of how the parser engine creates the internal representation of timestamps:

Thus, if you give the parser only "May, 20" - it will become"1970-05-20 00:00:00.000"

AnyChart Stock gives you the ability to alter Base Date using the base_date attribute of the <date_time> node; the date can be set according to the rules described in Input Date-Time Format.

The ability to set Base Date helps to avoid redundancy in timestamps; see sample XML below - it contains data with a millisecond precision and to avoid redundancy uses the base_date value:

XML/JSON Syntax
Plain code
01 <data_set id="dataSet1" source_mode="InternalData" date_time_column="0">
02   <locale>
03     <date_time base_date="2009-01-12 13:44:56.000">
04       <format><![CDATA[%fff]]></format>
05     </date_time>
06   </locale>
08   <csv_data><![CDATA[044,244.4
09 046,231.73
10 048,178.89
11 052,287.71
12 054,145.95
13 056,198.24
14 058,170.12
15 060,164.63
16 062,211.89]]></csv_data>
17 </data_set>
01{
02  id: "dataSet1",
03  sourceMode: "InternalData",
04  dateTimeColumn: 0,
05  locale: {
06    dateTime: {
07      baseDate: "2009-01-12 13:44:56.000",
08      format: "%fff"
09    }
10  },
11  csvSettings: {
12    ignoreFirstRow: false,
13    rowsSeparator: "\n",
14    columnsSeparator: ","
15  },
16  csvData: "044,244.4\r\n046,231.73\r\n048,178.89\r\n052,287.71\r\n054,145.95\r\n056,198.24\r\n058,170.12\r\n060,164.63\r\n062,211.89"
17}

As you can see here, the use of this method allows making data sets much smaller, and, moreover, parsing much faster. These two facts allow to gain a great improvement in the performance.

The table below shows a sample use of the Base Date method. The first column contains the formatting mask, description and base date; second column - timestamp as it could be set in the data set; and the third column - the resulting values that would be created by the parser and used for drawing the chart:

Description Timestamp Result Timestamp
24-hour intraday time.

Mask: "%HH:%mm"
Base Date: 2010-03-29

01:00 2010-03-29 01:00:00.000
13:45 2010-03-29 13:45:00.000
16:55 2010-03-29 16:55:00.000
23:34 2010-03-29 23:34:00.000
12-hour formatted time.

Mask: "%h:%mm %tt"
Base Date: 2010-03-29

1:00 AM 2010-03-29 01:00:00.000
1:45 PM 2010-03-29 13:45:00.000
4:55 PM 2010-03-29 16:55:00.000
11:34 PM 2010-03-29 23:34:00.000
Minutes and second within one hour.

Mask: "%mm:%ss"
Base Date: 2010-03-29 16

00:00 2010-03-29 16:00:00.000
10:30 2010-03-29 16:10:30.000
15:20 2010-03-29 16:15:20.000
59:30 2010-03-29 16:59:30.000
Millisecond precision within one hour.

Mask: "%mm:%ss.%fff"
Base Date: 2010-03-29 16

00:00.031 2010-03-29 16:00:00.031
10:30.581 2010-03-29 16:10:30.581
15:20.322 2010-03-29 16:15:20.322
59:30.999 2010-03-29 16:59:30.999
Millisecond precision within one hour.

Mask: "%mm:%ss.%fff"
Base Date: Not set

00:00.031 1970-01-01 00:00:00.031
10:30.581 1970-01-01 00:10:30.581
15:20.322 1970-01-01 00:15:20.322
59:30.999 1970-01-01 00:59:30.999
Year only.

Mask: "%yyyy"
Base Date: Not set

1991 1991-01-01 00:00:00.000
1992 1992-01-01 00:00:00.000
1993 1993-01-01 00:00:00.000
1994 1994-01-01 00:00:00.000
Month and year only.

Mask: "%MM/%yyyy"
Base Date: Not set

12/1991 1991-12-01 00:00:00.000
01/1992 1992-01-01 00:00:00.000
02/1992 1992-02-01 00:00:00.000
03/1992 1992-03-01 00:00:00.000

The live sample below uses data set that uses base date:

Live Sample:  Input Data Sample - Using Base Timestamp

Note: When adding points using appendData(), the base date and formatting mask must too be taken into account.

to top

Timestamp Offset

When defining a data set, you can set timestamps offset specified in hours. This may be useful when the data is created in one time zone and then viewed in a different one.

For example, suppose there is a server broadcasting a live feed from Hong Kong Stock Exchange (HKEX), where the trading hours are specified for the China time zone; if a viewer from Paris sees the chart created with AnyChart Stock based on the original values, he would see the 6-hour offset from his local time. With the time offset configured, the same user would see the same chart, now with his local time on it.

You can set time offset on the server side, by making modifications in the initial data set, but using AnyChart Stock's built-in time offset setting can make the server-side script lighter, shifting the load to clients.

To set time offset, use the offset attribute in the <date_time> node; it accepts values in hours, which can be positive, negative or fractional.

The sample XML below shows how to set a +6.5-hours offset:

XML/JSON Syntax
Plain code
01 <data_set id="dataSet1" source_mode="InternalData" date_time_column="0">
02   <locale>
03     <date_time offset="6.5">
04       <format><![CDATA[%M/%d/%yyyy %h:%mm:%ss %tt]]></format>
05     </date_time>
06   </locale>
08   <csv_data><![CDATA[4/8/2010 1:32:00 PM,10857.8398
09 4/8/2010 1:33:00 PM,10854.9697
10 4/8/2010 1:34:00 PM,10860.4102
11 4/8/2010 1:35:00 PM,10859.7305
12 4/8/2010 1:36:00 PM,10858.8203
13 4/8/2010 1:37:00 PM,10857.9199]]></csv_data>
14 </data_set>
01{
02  id: "dataSet1",
03  sourceMode: "InternalData",
04  dateTimeColumn: 0,
05  locale: {
06    dateTime: {
07      offset: 6.5,
08      format: "%M/%d/%yyyy %h:%mm:%ss %tt"
09    }
10  },
11  csvSettings: {
12    ignoreFirstRow: false,
13    rowsSeparator: "\n",
14    columnsSeparator: ","
15  },
16  csvData: "4/8/2010 1:32:00 PM,10857.8398\r\n4/8/2010 1:33:00 PM,10854.9697\r\n4/8/2010 1:34:00 PM,10860.4102\r\n4/8/2010 1:35:00 PM,10859.7305\r\n4/8/2010 1:36:00 PM,10858.8203\r\n4/8/2010 1:37:00 PM,10857.9199"
17}

The live sample below demonstrates how several data sets can use the same CSV table for different charts. One chart could show data according to the original timestamps, and the other one - with the -4.0 hours (four hours back) offset:

Live Sample:  Input Data Sample - Settings Timestamps Offset

Note: If on your chart you use Event Markers, and they are bound to a series that shows offset values, the offset must be used in the Event Markers as well. You can learn how to do that for Event Markers in Event Markers: Timestamp Offset.

to top

Number Format

Decimal and thousand separators vary from country to country; to use values in a local standard, you need to use the decimal_separator and thousands_separator attributes of the <number> node to define custom separators.

Here is a sample XML configuration that shows how to make the parser understand values like "23,8712", where comma (",") is used as the decimal separator:

XML/JSON Syntax
Plain code
01 <data_set id="dataSet1" source_mode="InternalData" date_time_column="0">
02   <locale>
04     <date_time>
05       <format><![CDATA[%yyyy-%MM-%dd]]></format>
06     </date_time>
07   </locale>
09   <csv_data><![CDATA[Date,Open,High,Low,Close
10 2009-10-01,"10'877,26","10'896,99","10'877,26","10'896,99"
11 2009-10-02,"10'863,51","10'876,73","10'862,83","10'876,73"
12 2009-10-03,"10'857,84","10'863,21","10'857,84","10'863,21"
13 2009-10-04,"10'854,97","10'858,82","10'852,93","10'857,92"
14 2009-10-05,"10'860,41","10'860,41","10'854,29","10'855,35"
15 2009-10-06,"10'859,73","10'861,62","10'858,82","10'861,09"
16 2009-10-07,"10'858,82","10'863,58","10'858,37","10'859,65"
17 2009-10-08,"10'857,92","10'860,94","10'857,92","10'858,52"
18 2009-10-09,"10'863,28","10'863,96","10'857,99","10'858,22"]]></csv_data>
19 </data_set>
01{
02  id: "dataSet1",
03  sourceMode: "InternalData",
04  dateTimeColumn: 0,
05  locale: {
06    number: {
07      decimalSeparator: ",",
08      thousandsSeparator: "'"
09    },
10    dateTime: {
11      format: "%yyyy-%MM-%dd"
12    }
13  },
14  csvSettings: {
15    ignoreFirstRow: true,
16    rowsSeparator: "\n",
17    columnsSeparator: ","
18  },
19  csvData: "Date,Open,High,Low,Close\r\n2009-10-01,\"10'877,26\",\"10'896,99\",\"10'877,26\",\"10'896,99\"\r\n2009-10-02,\"10'863,51\",\"10'876,73\",\"10'862,83\",\"10'876,73\"\r\n2009-10-03,\"10'857,84\",\"10'863,21\",\"10'857,84\",\"10'863,21\"\r\n2009-10-04,\"10'854,97\",\"10'858,82\",\"10'852,93\",\"10'857,92\"\r\n2009-10-05,\"10'860,41\",\"10'860,41\",\"10'854,29\",\"10'855,35\"\r\n2009-10-06,\"10'859,73\",\"10'861,62\",\"10'858,82\",\"10'861,09\"\r\n2009-10-07,\"10'858,82\",\"10'863,58\",\"10'858,37\",\"10'859,65\"\r\n2009-10-08,\"10'857,92\",\"10'860,94\",\"10'857,92\",\"10'858,52\"\r\n2009-10-09,\"10'863,28\",\"10'863,96\",\"10'857,99\",\"10'858,22\""
20}

Note: If you have to use comma (",") for the decimal or thousand separator, and you cannot avoid this, you must enclose the values in double quotes. Learn more about this in the CSV Settings and CSV Table Requirements section.

The live sample below demonstrates how a custom number formatting in data set can be implemented with AnyChart Stock:

Live Sample:  Input Data Sample - Settings Number Format

to top

Performance Improvement Recommendations

If you have the full control over your data source and can create those in any format, please consider the recommendations of this section; they will help you to improve the component's and application's performance.

1. Table Size

A CSV table can contain thousands of rows, and it may be useful to analyze it and check whether it is redundant. Each cell with a timestamp or value may contain unnecessary information, which is not actually required.

Data redundancy may cause the following problems:

Table Size Reduction Recommendations:

 

2. Parsing Speed

A CSV table parsing speed depends on many factors, and this section highlights the most significant of those. Please go through this checklist if you happen to be dissatisfied with the performance of the component or your application.

Not recommended:

Recommended:

This chart shows the comparison of processing speeds for different timestamps - the bar names are timestamps formatting strings and samples, and the bar length is the processing time (in milliseconds) for 50.000 timestamps in the respective format:

This test has been performed on a PC with the following specifications:

to top