Creating Event Markers

Overview

This article covers the mechanism of adding Event Markers to a chart in the configuration file. The component is capable of displaying a large number of event markers; technically, you are not anyhow restricted when forming the list. However, using more than 3000 markers simultaneously is not recommended, as it may seriously downgrade the performance of the component.

The actual event markers are defined in the <event_markers> node, located at the following nesting level of the XML structure:

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   <event_markers />
04 </stock>
01{
02  eventMarkers: {}
03}

The complete structure of the node along with all possible event marker element settings can be learnt in XML Reference.

to top

Declaring Event Markers in Configuration File

Event Markers are added to chart as the so-called "groups", which are technically collections of event markers. Using groups is very convenient, as they allow adding visual and functional settings for a whole set of markers without creating configuration duplicates for each marker.

Declaring and Customizing Group

Here is a listing showing where groups are to be added:

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   <event_markers>
04     <groups>
05       <group />
06       <group />
07       <group />
08     </groups>
09   </event_markers>
10 </stock>
01{
02  eventMarkers: {
03    groups: [
04      {},
05      {},
06      {}
07    ]
08  }
09}

As you can see on the listing, groups are declared as a set of the <group> nodes, the number of which is not limited...

Event markers cannot appear on a chart on their own; they (or, to be exact, the group) need a data series they are going to be bound to. Each group _must_ have a chart identifier and series identifier on that chart that the group of event markers would be bound to.

Take a look at this listing - identifiers are set for the chart and for the series. For the chart that's idMainChart, and for the two series - idSeries1 and idSeries2:

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   <settings>
04     <charts>
05       <chart id="idMainChart">
06         <series_list>
07           <series id="idSeries1" data_provider="dp1" color="#0066DD">
08             <name><![CDATA[Series1]]></name>
09           </series>
10           <series id="idSeries2" data_provider="dp2" color="#771010">
11             <name><![CDATA[Series2]]></name>
12           </series>
13         </series_list>
14       </chart>
15     </charts>
16   </settings>
17 </stock>
01{
02  settings: {
03    charts: [
04      {
05        id: "idMainChart",
06        seriesList: [
07          {
08            id: "idSeries1",
09            dataProvider: "dp1",
10            color: "#0066DD",
11            name: "Series1"
12          },
13          {
14            id: "idSeries2",
15            dataProvider: "dp2",
16            color: "#771010",
17            name: "Series2"
18          }
19        ]
20      }
21    ]
22  }
23}

The next listing demonstrates using these identifiers for binding groups of event markers to data series:

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   <event_markers>
04     <groups>
05       <group chart="idMainChart" series="idSeries1" format="A">
06         <locale>
07           <date_time>
08             <format><![CDATA[%yyyy-%MM-%dd]]></format>
09           </date_time>
10         </locale>
11         <events>
12           <event locale_based_date="2009-04-14" />
13           <event locale_based_date="2008-11-18" />
14           <event locale_based_date="2008-10-16" />
15         </events>
16       </group>
17       <group chart="idMainChart" series="idSeries2" format="B">
18         <locale>
19           <date_time>
20             <format><![CDATA[%yyyy-%MM-%dd]]></format>
21           </date_time>
22         </locale>
23         <events>
24           <event locale_based_date="2009-07-18" />
25           <event locale_based_date="2009-07-27" />
26           <event locale_based_date="2009-10-12" />
27         </events>
28       </group>
29     </groups>
30   </event_markers>
31   <settings>
32     <charts>
33       <chart id="idMainChart">
34         <series_list>
35           <series id="idSeries1" data_provider="dp1" color="#0066DD">
36             <name><![CDATA[Series1]]></name>
37           </series>
38           <series id="idSeries2" data_provider="dp2" color="#771010">
39             <name><![CDATA[Series2]]></name>
40           </series>
41         </series_list>
42       </chart>
43     </charts>
44   </settings>
45 </stock>
01{
02  eventMarkers: {
03    groups: [
04      {
05        chart: "idMainChart",
06        series: "idSeries1",
07        format: "A",
08        locale: {
09          dateTime: {
10            format: "%yyyy-%MM-%dd"
11          }
12        },
13        events: [
14          {
15            localeBasedDate: "2009-04-14"
16          },
17          {
18            localeBasedDate: "2008-11-18"
19          },
20          {
21            localeBasedDate: "2008-10-16"
22          }
23        ]
24      },
25      {
26        chart: "idMainChart",
27        series: "idSeries2",
28        format: "B",
29        locale: {
30          dateTime: {
31            format: "%yyyy-%MM-%dd"
32          }
33        },
34        events: [
35          {
36            localeBasedDate: "2009-07-18"
37          },
38          {
39            localeBasedDate: "2009-07-27"
40          },
41          {
42            localeBasedDate: "2009-10-12"
43          }
44        ]
45      }
46    ]
47  },
48  settings: {
49    charts: [
50      {
51        id: "idMainChart",
52        seriesList: [
53          {
54            id: "idSeries1",
55            dataProvider: "dp1",
56            color: "#0066DD",
57            name: "Series1"
58          },
59          {
60            id: "idSeries2",
61            dataProvider: "dp2",
62            color: "#771010",
63            name: "Series2"
64          }
65        ]
66      }
67    ]
68  }
69}

As you can see on the listing, the <group> node has two attributes: chart and series. To bind a group of event markers to a specific series, chart attribute must accept the identifier value of the chart the series is located on, and the series attribute - identifier of the series on the chart the group of markers would be bound to.

Binding groups of event markers is covered in different variations accompanied by live examples in Binding to Series in Different Variations.

Here is the table of all attributes, available in the <group> node:

Attribute Possible Values Description
chart Any existing chart identifier. Mandatory parameter. Chart identifier, containing a series, which the group of event markers is to be bound to.
series Any existing series identifier. Mandatory parameter. Series identifier, which the group of event markers is to be bound to.
id Any string. Group identifier used by external methods for different operations over the group.
visible true
false
If this attribute is set to false, this group of markers will be invisible. Later on, when using the chart on a page, you can make the group be visible by using the external showEventMarkerGroup method.
direction Up
Down
Defines the drawing direction for markers of the group.
position Axis
Series
SeriesPositive
SeriesNegative
Defines the position for plotting markers that belong to the group.
format Any text character. Defines the character to be displayed over all event markers in this group.
field_type Low
High
Open
Close
Value
Volume
Custom
Together with field_custom_type_name attribute determines a field of the referenced series data provider that is used to determine anchor Y position for all elements of this group (if the group is not set to be placed on an axis). Learn more.
field_custom_type_name String Together with field_type attribute determines a field of the referenced series data provider that is used to determine anchor Y position for all elements of this group (if the group is not set to be placed on an axis). Learn more.

The use of some of these attributes is covered in Event Markers: General & Visual Settings.

to top

Adding Events to Group

Once you have a group added and bound to some data series, you need to fill it up with event markers.

Markers are added as a list to the <events> node; the number of the markers is not limited. An event marker is described in the <event> node. Below is the sample XML syntax for adding markers to group:

XML/JSON Syntax
Plain code
02   <groups>
03     <group chart="idChart" series="idSeries2">
04       <locale>
05         <date_time>
06           <format><![CDATA[%yyyy-%MM-%dd]]></format>
07         </date_time>
08       </locale>
09       <events>
10         <event locale_based_date="2009-07-18" id="em1" format="A" />
11         <event locale_based_date="2009-07-27" id="em2" format="B" />
12         <event locale_based_date="2009-10-12" id="em3" format="C" />
13       </events>
14     </group>
15   </groups>
01{
02  groups: [
03    {
04      chart: "idChart",
05      series: "idSeries2",
06      locale: {
07        dateTime: {
08          format: "%yyyy-%MM-%dd"
09        }
10      },
11      events: [
12        {
13          localeBasedDate: "2009-07-18",
14          id: "em1",
15          format: "A"
16        },
17        {
18          localeBasedDate: "2009-07-27",
19          id: "em2",
20          format: "B"
21        },
22        {
23          localeBasedDate: "2009-10-12",
24          id: "em3",
25          format: "C"
26        }
27      ]
28    }
29  ]
30}

In each <event> node, you must specify its timestamp using the date or locale_based_date attribute to define the date it is bound to, date has the fixed format and locale_based_date can be defined in <locale> node.

More detailed description of configuring or not configuring locale and setting timestamps for event markers is available in Event Markers: Date-Time Input Locale and article.

Here is the complete list of attributes, available in the <event> node:

Attribute Possible Values Description
date Timestamp in fixed chart settings format. Timestamp this event marker would be bound to. Timestamp is set as a string and must comply with the format defined in Date Time Values in Chart Settings. Either this or locale_based_date attribute should be defined, but this has the priority, if both are specified.
locale_based_date Timestamp value according to the locale format. Timestamp this event marker would be bound to. Timestamp is set as a string and must comply with the format defined in the <locale> node of the group this event marker is added to. Either this or date attribute should be defined.
id String identifier. Sets string identifier, which enables using this event marker by external methods.
selected true
false
If this attribute is set to true, this event marker will be selected. By default the parameter is set to false.
visible true
false
If this attribute is set to false, this event marker will be invisible. Later on, you can make it visible by using the external method showEventMarker.
direction Up
Down
Defines the drawing direction for the event marker.
position Axis
Series
SeriesPositive
SeriesNegative
Defines the position this event marker will be plotted at. By default, it is set to Series.
format Any text character. Defines the character to be displayed over this event marker.

The use of some of these attributes is covered in Event Markers: General & Visual Settings.

Here is the first final live sample that demonstrates how you can add event markers with the configuration file:

Live Sample:  Event Markers

There is another way for adding event markers, bypassing the configuration file - that's adding the markers with the JavaScript library supplied with the component. With this library, you can dynamically add, delete and modify existing event markers on the chart.

Handling event markers with the JavaScript library is covered in a bunch of samples in Online HTML/JavaScript Samples Center: Working with Event Markers section.

to top

Binding to Series in Different Variations

A group of event markers can be bound to any data series and even to technical indicators. It is also worth noticing that the binding works in any value axis mode; for example, in the comparison modes, covered in Y-Axes Settings.

1. Example - One group of markers is bound to one series:

Live Sample:  Binding Event Markers - Single Chart and Single Series

2. Example - Two series with one group of markers bound to each series:

Live Sample:  Binding Event Markers - Single Chart and Two Series

3. Example - Two charts with one series on each chart and one group of markers bound to each series:

Live Sample:  Binding Event Markers - Two Charts and Two Series

4. Example - One series with two groups of markers bound to it. The value axis is in the PercentChanges mode:

Live Sample:  Binding Event Markers - One Series and Two Event Marker Groups

5. Example - Binding a group of markers to a series visualizing one of the parameters of the Stochastic Oscillator technical indicator:

Live Sample:  Binding Event Markers - Technical Indicators

to top

Using Custom Attributes

Each event marker can carry the so-called custom attributes, which in the essence are the accompanying data set in the format of string values with some identifier. Later on, you can use that data in tooltips or process it when obtaining events from event markers.

Below is the XML syntax for adding custom attributes to an event marker:

XML/JSON Syntax
Plain code
01 <event locale_based_date="2009-04-14">
02   <attributes>
03     <attr name="Desc"><![CDATA[Additional Information!]]></attr>
04     <attr name="Url"><![CDATA[http://www.anychart.com]]></attr>
05   </attributes>
06 </event>
01{
02  localeBasedDate: "2009-04-14",
03  attributes: {
04    Desc: "Additional Information!",
05    Url: "http://www.anychart.com"
06  }
07}

As you can see on the listing, custom attributes are set as a list in the <attr> node, each one of which requires an identifier specified in the name parameter; e.g.: <attr name="Url">. The value of the attribute is to be defined inside the <attr> node. When using special characters, make sure to use the CDATA block.

For an example of using custom attributes, we could review a live sample using the standard tooltips for event markers:

Live Sample:  Event Markers - Using Custom Attributes in Tooltips

The detailed coverage for using built-in tooltips is available in Event Markers: Using Tooltips.

Besides that, custom attributes can be obtained when processing events from event markers. Here are the custom samples that use such technique:

Online HTML/JavaScript Sample
Online HTML/JavaScript Sample
Online HTML/JavaScript Sample

 

to top