X-Axis Markers

Overview

AnyChart Stock supports "Axis Markers", which allow showing trends, limits, highlighting date time intervals of interest and other important information.

The current version supports two types of markers:

Any marker can have several labels positioned by the axis marker. The illustration below demonstrates the both marker types:

Axis Markers are bound to the dates axis; you can add any number of the markers to a chart to be displayed.

Here is a sample XML that shows where the marker configuration parameters are to be placed:

XML/JSON Syntax
Plain code
01 <chart>
02   <x_axis>
03     <axis_markers>
04       <line_markers>
05         <line_marker date="2004-05-13" />
06       </line_markers>
07       <range_markers>
08         <range_marker start_date="2008-08-10" end_date="2009-07-02" />
09       </range_markers>
10     </axis_markers>
11   </x_axis>
12 </chart>
01{
02  xAxis: {
03    axisMarkers: {
04      lineMarkers: [
05        {
06          date: "2004-05-13"
07        }
08      ],
09      rangeMarkers: [
10        {
11          startDate: "2008-08-10",
12          endDate: "2009-07-02"
13        }
14      ]
15    }
16  }
17}

As you can see in the sample, line markers are defined in the <line_marker> node, and Range Markers - in the <range_marker> node.

to top

Line Markers

A line marker displays one date on the axis in the form of a line and/or a set of labels.

Adding Line Markers

When creating a line marker, you should specify one exact date on the axis. The number of markers is not limited, and they all are defined with a list of the <line_marker> nodes.

This sample XML demonstrates the definition of three line markers:

XML/JSON Syntax
Plain code
01 <chart>
02   <x_axis>
03     <axis_markers>
04       <line_markers>
05         <line_marker date="2004-05-13" />
06         <line_marker date="2006-01-02" />
07         <line_marker date="2008-11-23" />
08       </line_markers>
09     </axis_markers>
10   </x_axis>
11 </chart>
01{
02  xAxis: {
03    axisMarkers: {
04      lineMarkers: [
05        {
06          date: "2004-05-13"
07        },
08        {
09          date: "2006-01-02"
10        },
11        {
12          date: "2008-11-23"
13        }
14      ]
15    }
16  }
17}

date attribute set axis marker position. This date should follow formatting rules described in Input Date-Time Format article.

The live sample below demonstrates a line marker in action:

Live Sample:  X-Axis Markers - Line Marker

to top

Line Settings

A line marker can be drawn as solid or dashed line. The sample XML below demonstrates them both:

XML/JSON Syntax
Plain code
01 <chart>
02   <x_axis>
03     <axis_markers>
04       <line_markers>
05         <line_marker date="2005-01-02">
06           <line thickness="2" color="DarkRed" dashed="true" dash_length="10" dash_space="10" />
07         </line_marker>
08         <line_marker date="2007-10-27">
09           <line thickness="2" color="Green" dashed="false" opacity="0.5" />
10         </line_marker>
11       </line_markers>
12     </axis_markers>
13   </x_axis>
14 </chart>
01{
02  xAxis: {
03    axisMarkers: {
04      lineMarkers: [
05        {
06          date: "2005-01-02",
07          line: {
08            thickness: 2,
09            color: "DarkRed",
10            dashed: true,
11            dashLength: 10,
12            dashSpace: 10
13          }
14        },
15        {
16          date: "2007-10-27",
17          line: {
18            thickness: 2,
19            color: "Green",
20            dashed: false,
21            opacity: 0.5
22          }
23        }
24      ]
25    }
26  }
27}

As you can see in the sample, the line is configured in the <line> subnode. To make the line dashed, you are to set the dashed attribute to true and (optionally) define the dash_length and dash_space.

The live sample below demonstrates the above configuration in action:

Live Sample:  X-Axis Markers - Line Settings

Learn more about line settings for line markers in XML Reference.

to top

Labels

An axis marker can have an unlimited number of labels - depending on your task, you can add one, two, three or more labels placed in different areas, with different text and appearance.

Labels are defined by the set of the <label> nodes. For example:

XML/JSON Syntax
Plain code
01 <line_marker date="2008-02-17">
02   <labels>
03     <label />
04     <label />
05     <label />
06   </labels>
07 </line_marker>
01{
02  date: "2008-02-17",
03  labels: [
04    {},
05    {},
06    {}
07  ]
08}

Below follows the description of label configuration.

Positioning

A label can be placed on any position relative to the marker line inside the data plotting area. Be default, labels are placed to the right of the marker line at the top of the chart.

The following attributes of the <label> node are used for defining label position:

Attribute Possible Values Description
anchor Top
Center
Bottom
Sets label anchor.
valign Top
Center
Bottom
Sets label vertical alignment.
halign Left
Center
Right
Sets label horizontal alignment.
x_padding Any number Sets label X padding.
y_padding Any number Sets label Y padding.

Here is a sample XML that demonstrates defining a label position:

XML/JSON Syntax
Plain code
01 <line_marker date="2009-03-03">
02   <labels>
03     <label anchor="Center" valign="Top" halign="Center" x_padding="0" y_padding="4" />
04   </labels>
05 </line_marker>
01{
02  date: "2009-03-03",
03  labels: [
04    {
05      anchor: "Center",
06      valign: "Top",
07      halign: "Center",
08      xPadding: 0,
09      yPadding: 4
10    }
11  ]
12}

to top

Text and Tokens

To define a label text, use the <format> node, you can use either a static text or a {%Date} token, which would be replaced with the actual value set in the date attribute of <line_marker> node.

Here is a sample XML that shows how to define a label text:

XML/JSON Syntax
Plain code
01 <line_marker date="2009-03-03">
02   <labels>
03     <label>
04       <format><![CDATA[Value: {%Date}]]></format>
05     </label>
06   </labels>
07 </line_marker>
01{
02  date: "2009-03-03",
03  labels: [
04    {
05      format: "Value: {%Date}"
06    }
07  ]
08}

With this formatting, the label would display the following text: "Date: 2009-03-03". The {%Date} token can be formatted just as any other token - see Date-Time Formatting for more information.

to top

Font

Label font is configured in the typical <font> node.

There are two major options for configuring label font:

This XML sample demonstrates how to define font settings with the <font> node:

XML/JSON Syntax
Plain code
01 <line_marker date="2009-03-03">
02   <labels>
03     <label>
04       <font family="Verdana" size="9" color="#335533" bold="true" />
05       <format><![CDATA[{%Date}]]></format>
06     </label>
07   </labels>
08 </line_marker>
01{
02  date: "2009-03-03",
03  labels: [
04    {
05      font: {
06        family: "Verdana",
07        size: 9,
08        color: "#335533",
09        bold: true
10      },
11      format: "{%Date}"
12    }
13  ]
14}

Another example - doing the same with the HTML tag:

XML/JSON Syntax
Plain code
01 <line_marker date="2009-03-03">
02   <labels>
03     <label>
04       <font render_as_html="true" />
05       <format><![CDATA[Date: <b><font color="#883333">{%Date}</font></b>]]></format>
06     </label>
07   </labels>
08 </line_marker>
01{
02  date: "2009-03-03",
03  labels: [
04    {
05      font: {
06        renderAsHtml: true
07      },
08      format: "Date: <b><font color=\"#883333\">{%Date}</font></b>"
09    }
10  ]
11}

Find out more about font settings and HTML formatting in Font Configuration.

to top

Background

You can enable background to make the text in a label easier to read. Background is configured in the <background> node.

The sample XML below demonstrates how to define label background:

XML/JSON Syntax
Plain code
01 <line_marker date="2009-03-03">
02   <labels>
03     <label anchor="Top" x_padding="5" y_padding="5" valign="Top" halign="Left">
04       <format><![CDATA[Date: {%Date}]]></format>
05       <font family="Tahoma" size="9" bold="true" color="#333333" />
06       <background enabled="true">
07         <fill enabled="true" type="Solid" color="#FEFFE6" opacity="1" />
08         <corners type="Rounded" all="4" />
09         <border enabled="true" color="#CBAF87" />
10         <inside_margin left="10" />
11       </background>
12     </label>
13   </labels>
14 </line_marker>
01{
02  date: "2009-03-03",
03  labels: [
04    {
05      anchor: "Top",
06      xPadding: 5,
07      yPadding: 5,
08      valign: "Top",
09      halign: "Left",
10      format: "Date: {%Date}",
11      font: {
12        family: "Tahoma",
13        size: 9,
14        bold: true,
15        color: "#333333"
16      },
17      background: {
18        enabled: true,
19        fill: {
20          enabled: true,
21          type: "Solid",
22          color: "#FEFFE6",
23          opacity: 1
24        },
25        corners: {
26          type: "Rounded",
27          all: 4
28        },
29        border: {
30          enabled: true,
31          color: "#CBAF87"
32        },
33        insideMargin: {
34          left: 10
35        }
36      }
37    }
38  ]
39}

to top

Sample with All Settings

Take a look at the sample below that uses all the settings described above, including HTML text formatting:

Live Sample:  X-Axis Markers - Line Marker with Labels

to top

Range Markers

A range marker is bound to two axis dates: start and end. It appears as two lines and a filler between them. Just as line marker, range marker can have an unlimited number of labels, but these labels have more anchors.

Adding Range Markers

When adding a range marker, you should define the limits that you want to show on the plot. The number of markers is not limited, and they all are defined in the list of the <range_marker> nodes .

This sample XML demonstrates adding three range markers to the primary axis:

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>
06         <x_axis>
07           <axis_markers>
08             <range_markers>
09               <range_marker start_date="2003-01-02" end_date="2004-06-17" />
10               <range_marker start_date="2004-06-17" end_date="2005-08-13" />
11               <range_marker start_date="2005-08-13" end_date="2008-11-10" />
12             </range_markers>
13           </axis_markers>
14         </x_axis>
15       </chart>
16     </charts>
17   </settings>
18 </stock>
01{
02  settings: {
03    charts: [
04      {
05        xAxis: {
06          axisMarkers: {
07            rangeMarkers: [
08              {
09                startDate: "2003-01-02",
10                endDate: "2004-06-17"
11              },
12              {
13                startDate: "2004-06-17",
14                endDate: "2005-08-13"
15              },
16              {
17                startDate: "2005-08-13",
18                endDate: "2008-11-10"
19              }
20            ]
21          }
22        }
23      }
24    ]
25  }
26}

As you can see here, the limits of the range are set by the start_date and end_date attributes. These dates should follow formatting rules described in Input Date-Time Format article.

Here is a live sample for a range marker between "2007-01-02" and "2008-05-15:

Live Sample:  X-Axis Markers - Range Marker

This is what a range marker looks like by default; you can tune up the visual settings to customize its appearance. The customization is going to be covered right next.

to top

Visual Settings

A range marker consists of three elements:

The lines can be either solid or dashed; the filler can be solid or gradient. The sample XML below demonstrates how to configure the appearance of a range marker:

XML/JSON Syntax
Plain code
01 <range_marker start_date="2008-01-12" end_date="2009-08-11">
02   <start_line color="Red" dashed="true" dash_length="3" dash_space="3" />
03   <end_line color="Red" dashed="true" dash_length="3" dash_space="3" />
04   <fill opacity="0.05" />
05 </range_marker>
01{
02  startDate: "2008-01-12",
03  endDate: "2009-08-11",
04  startLine: {
05    color: "Red",
06    dashed: true,
07    dashLength: 3,
08    dashSpace: 3
09  },
10  endLine: {
11    color: "Red",
12    dashed: true,
13    dashLength: 3,
14    dashSpace: 3
15  },
16  fill: {
17    opacity: 0.05
18  }
19}

The live sample below demonstrates two range markers with configured visual settings:

Live Sample:  X-Axis Markers - Range Marker Visual Settings

Find out more about fill configuration in Background Tutorial and XML Reference.

to top

Using Labels

An axis marker can have an unlimited number of labels - depending on your task, you can add one, two, three or more labels placed in different areas, with different text and appearance.

Labels are defined by the set of the <label> nodes. For example:

XML/JSON Syntax
Plain code
01 <range_marker start_date="2008-01-13" end_date="2009-10-11">
02   <labels>
03     <label anchor="BottomCenter" x_padding="0" valign="Top" halign="Center">
04       <format><![CDATA[{%StartDate}{"%MMM %dd, %yyyy"} - {%EndDate}{"%MMM %dd, %yyyy"}]]></format>
05       <font family="Tahoma" size="9" bold="true" color="#333333" />
06     </label>
07   </labels>
08 </range_marker>
01{
02  startDate: "2008-01-13",
03  endDate: "2009-10-11",
04  labels: [
05    {
06      anchor: "BottomCenter",
07      xPadding: 0,
08      valign: "Top",
09      halign: "Center",
10      format: "{%StartDate}{\"%MMM %dd, %yyyy\"} - {%EndDate}{\"%MMM %dd, %yyyy\"}",
11      font: {
12        family: "Tahoma",
13        size: 9,
14        bold: true,
15        color: "#333333"
16      }
17    }
18  ]
19}

Below follows the description of label customization.

Positioning

A label can be placed on any position relative to the marker line inside the data plotting area. Be default, labels are placed in the center-right of the plotting area.

The following attributes of the <label> node are used for defining label position:

Attribute Possible Values Description
anchor LeftTop
RightTop
LeftBottom
RightBottom
LeftCenter
RightCenter
TopCenter
BottomCenter
Center
Sets label anchor.
valign Top
Center
Bottom
Sets label vertical alignment.
halign Left
Center
Right
Sets label horizontal alignment.
x_padding Any number Sets label X padding.
y_padding Any number Sets label Y padding.

Here is a sample XML that demonstrates defining a label position:

XML/JSON Syntax
Plain code
01 <range_marker start_date="2008-08-10" end_date="2009-07-02">
02   <labels>
03     <label anchor="RightTop" valign="Bottom" halign="Left" x_padding="4" y_padding="4" />
04   </labels>
05 </range_marker>
01{
02  startDate: "2008-08-10",
03  endDate: "2009-07-02",
04  labels: [
05    {
06      anchor: "RightTop",
07      valign: "Bottom",
08      halign: "Left",
09      xPadding: 4,
10      yPadding: 4
11    }
12  ]
13}

With such settings label is placed in the top right corner of the area.

to top

Text and Tokens

To define a label text, use the <format> node, you can use either a static text or the {%StartDate} and {%EndDate} tokens, which would be replaced with the actual value set in the start_date and end_date attributes of the <range_marker> node.

Here is a sample XML that shows how to define a label text:

XML/JSON Syntax
Plain code
01 <range_marker start_date="2008-08-10" end_date="2009-07-02">
02   <labels>
03     <label>
04       <format><![CDATA[Range: {%StartDate} - {%EndDate}]]></format>
05     </label>
06   </labels>
07 </range_marker>
01{
02  startDate: "2008-08-10",
03  endDate: "2009-07-02",
04  labels: [
05    {
06      format: "Range: {%StartDate} - {%EndDate}"
07    }
08  ]
09}

With this formatting, the label would display the following text: "Range: 2008-08-10 - 2009-07-02". The {%StartDate} and {%EndDate} tokens can be formatted just as any other token - see Date-Time Formatting for more information.

to top

Font

Label font is configured in the typical <font> node.

There are two major options for configuring label font:

This XML sample demonstrates defining font settings with the <font> node:

XML/JSON Syntax
Plain code
01 <range_marker start_date="2008-08-10" end_date="2009-07-02">
02   <labels>
03     <label>
04       <font family="Verdana" size="9" color="#335533" bold="true" />
05     </label>
06   </labels>
07 </range_marker>
01{
02  startDate: "2008-08-10",
03  endDate: "2009-07-02",
04  labels: [
05    {
06      font: {
07        family: "Verdana",
08        size: 9,
09        color: "#335533",
10        bold: true
11      }
12    }
13  ]
14}

Another example - doing the same with the HTML tag:

XML/JSON Syntax
Plain code
01 <range_marker start_date="2008-08-10" end_date="2009-07-02">
02   <labels>
03     <label>
04       <font render_as_html="true" />
05       <format><![CDATA[<b><font color="#883333">{%StartDate} - {%EndDate}</font></b>]]></format>
06     </label>
07   </labels>
08 </range_marker>
01{
02  startDate: "2008-08-10",
03  endDate: "2009-07-02",
04  labels: [
05    {
06      font: {
07        renderAsHtml: true
08      },
09      format: "<b><font color=\"#883333\">{%StartDate} - {%EndDate}</font></b>"
10    }
11  ]
12}

Find out more about font settings and HTML formatting in Font Configuration.

to top

Background

You can enable background to make the text in a label easier to read. Background is configured in the <background> node.

The sample XML below demonstrates how to define label background:

XML/JSON Syntax
Plain code
01 <range_marker start_date="2008-08-10" end_date="2009-07-02">
02   <labels>
03     <label anchor="RightCenter" x_padding="5" y_padding="0" valign="Center" halign="Left">
04       <format><![CDATA[Range: {%StartDate} - {%EndDate}]]></format>
05       <font family="Tahoma" size="9" bold="true" color="#333333" />
06       <background enabled="true">
07         <fill enabled="true" type="Solid" color="#FEFFE6" opacity="1" />
08         <corners type="Rounded" all="4" />
09         <border enabled="true" color="#CBAF87" />
10         <inside_margin left="5" right="5" />
11       </background>
12     </label>
13   </labels>
14 </range_marker>
01{
02  startDate: "2008-08-10",
03  endDate: "2009-07-02",
04  labels: [
05    {
06      anchor: "RightCenter",
07      xPadding: 5,
08      yPadding: 0,
09      valign: "Center",
10      halign: "Left",
11      format: "Range: {%StartDate} - {%EndDate}",
12      font: {
13        family: "Tahoma",
14        size: 9,
15        bold: true,
16        color: "#333333"
17      },
18      background: {
19        enabled: true,
20        fill: {
21          enabled: true,
22          type: "Solid",
23          color: "#FEFFE6",
24          opacity: 1
25        },
26        corners: {
27          type: "Rounded",
28          all: 4
29        },
30        border: {
31          enabled: true,
32          color: "#CBAF87"
33        },
34        insideMargin: {
35          left: 5,
36          right: 5
37        }
38      }
39    }
40  ]
41}

to top

Sample with All Settings

Take a look at the sample below that uses all the settings described above, including HTML text formatting:

Live Sample:  X-Axis Markers - Range Maerker with Labels

to top

Default Settings

If you use a lot of line or range markers with identical visual or label settings, it is better to use default settings to avoid settings duplication.

You can set default settings for all axis markers of X axis in:

Sample XML below shows how to set defaults for all markers:

XML/JSON Syntax
Plain code
01 <chart>
02   <x_axis>
03     <axis_markers>
04       <line_marker_defaults>
05         <line color="DarkRed" dashed="true" thickness="2" pixel_hinting="true" />
06         <labels>
07           <label anchor="Top" valign="Center" halign="Left" x_padding="10">
08             <format><![CDATA[{%Date}]]></format>
09             <font family="Verdana" bold="true" color="#333333" />
10             <background enabled="true">
11               <fill color="#FFFFFF" opacity="0.7" />
12             </background>
13           </label>
14         </labels>
15       </line_marker_defaults>
16       <range_marker_defaults>
17         <start_line color="DarkRed" dashed="true" thickness="2" pixel_hinting="true" />
18         <end_line color="DarkRed" dashed="true" thickness="2" pixel_hinting="true" />
19         <fill color="DarkRed" opacity="0.1" />
20         <labels>
21           <label anchor="Center" valign="Center" halign="Center" x_padding="0" y_padding="0">
22             <font family="Verdana" color="#333333" bold="true" />
23             <format><![CDATA[{%StartDate} - {%EndDate}]]></format>
24             <background enabled="true">
25               <fill color="#FFFFFF" opacity="0.7" />
26             </background>
27           </label>
28         </labels>
29       </range_marker_defaults>
30     </axis_markers>
31   </x_axis>
32 </chart>
01{
02  xAxis: {
03    axisMarkers: {
04      lineMarkerDefaults: {
05        line: {
06          color: "DarkRed",
07          dashed: true,
08          thickness: 2,
09          pixelHinting: true
10        },
11        labels: [
12          {
13            anchor: "Top",
14            valign: "Center",
15            halign: "Left",
16            xPadding: 10,
17            format: "{%Date}",
18            font: {
19              family: "Verdana",
20              bold: true,
21              color: "#333333"
22            },
23            background: {
24              enabled: true,
25              fill: {
26                color: "#FFFFFF",
27                opacity: 0.7
28              }
29            }
30          }
31        ]
32      },
33      rangeMarkerDefaults: {
34        startLine: {
35          color: "DarkRed",
36          dashed: true,
37          thickness: 2,
38          pixelHinting: true
39        },
40        endLine: {
41          color: "DarkRed",
42          dashed: true,
43          thickness: 2,
44          pixelHinting: true
45        },
46        fill: {
47          color: "DarkRed",
48          opacity: 0.1
49        },
50        labels: [
51          {
52            anchor: "Center",
53            valign: "Center",
54            halign: "Center",
55            xPadding: 0,
56            yPadding: 0,
57            font: {
58              family: "Verdana",
59              color: "#333333",
60              bold: true
61            },
62            format: "{%StartDate} - {%EndDate}",
63            background: {
64              enabled: true,
65              fill: {
66                color: "#FFFFFF",
67                opacity: 0.7
68              }
69            }
70          }
71        ]
72      }
73    }
74  }
75}

Live sample below shows how defaults for axis markers can be set and how certain marker settings can be reset:

Live Sample:  X-Axis Markers - Using Defaults

to top