Series Common Settings

Overview

AnyChart Stock Component supports 14 types of series. Each chart can contain any number of series, but it is not recommended to put more than ten series on one chart, for chart becomes unreadable when too many series are shown at the same time. Series of any type has some common settings and we will talk about them in this article. To learn more about specific settings for each type please see Series Types and Settings.

to top

Series Declaration

Series is a visual representation of the data provider on the chart. To show series on the chart you should declare it in the series list.

Sample XML to declare series:

XML/JSON Syntax
Plain code
01 <chart>
02   <series_list>
03     <series type="Line" data_provider="dp1" color="#DC3912" />
04     <series type="Line" data_provider="dp2" color="#12FF18" />
05     <series type="Line" data_provider="dp3" color="#5639DD" />
06     <series type="Line" data_provider="dp4" color="#E124AA" />
07   </series_list>
08 </chart>
01{
02  seriesList: [
03    {
04      type: "Line",
05      dataProvider: "dp1",
06      color: "#DC3912"
07    },
08    {
09      type: "Line",
10      dataProvider: "dp2",
11      color: "#12FF18"
12    },
13    {
14      type: "Line",
15      dataProvider: "dp3",
16      color: "#5639DD"
17    },
18    {
19      type: "Line",
20      dataProvider: "dp4",
21      color: "#E124AA"
22    }
23  ]
24}

As you can see series is defined using <series> node, with type, color and data_provider attributes.

type sets the type of the series and can be one of the following:

color sets the color of the series and dependent elements. See more about series coloring in Setting Color and using %Color token.

data_provider sets the data provider name with data for the series. See more about series and data providers in Understanding Data Model article.

Depending on the series type the data provider should contain specific named fields. Table below lists all series types and required fields:

Series Type Required fields
Line "Value" or "Close"
Spline "Value" or "Close"
SplineArea "Value" or "Close"
Bar "Value" or "Close"
Area "Value" or "Close"
RangeArea "High", "Low"
RangeBar "High", "Low"
RangeSplineArea "High", "Low"
StepLine "Value" or "Close"
StepLineArea "Value" or "Close"
Candlestick "Open", "High", "Low", "Close"
OHLC "Open", "High", "Low", "Close"
Marker "Value" or "Close"
Stick "Value" or "Close"

to top

Setting Color and using %Color token

By default all series are colored in black, to color series you should set its color explicitly.

Sample syntax to color the series:

XML/JSON Syntax
Plain code
01 <chart>
02   <series_list>
03     <series type="Line" data_provider="dp1" color="#DC3912" />
04     <series type="Line" data_provider="dp2" color="DarkRed" />
05     <series type="Line" data_provider="dp3" color="Rgb(120,40,120)" />
06     <series type="Line" data_provider="dp4" color="Hsb(150,79,85)" />
07   </series_list>
08 </chart>
01{
02  seriesList: [
03    {
04      type: "Line",
05      dataProvider: "dp1",
06      color: "#DC3912"
07    },
08    {
09      type: "Line",
10      dataProvider: "dp2",
11      color: "DarkRed"
12    },
13    {
14      type: "Line",
15      dataProvider: "dp3",
16      color: "Rgb(120,40,120)"
17    },
18    {
19      type: "Line",
20      dataProvider: "dp4",
21      color: "Hsb(150,79,85)"
22    }
23  ]
24}

The color can be set in different format, it can be hex code, web-constant, RGB or HSB macros, also you can use transform functions, for example: <series color="DarkColor(#FEFE00)"/>. Learn more about coloring in Using Colors article.

The color set for the series used to draw the series and other depended elements, such as legend item, tooltip and markers.

Wherever you configure the series you can set either a color constant or %Color token, which will be replaced by the value of color attribute upon rendering.

Here is a sample XML for lines and fill of Area series:

XML/JSON Syntax
Plain code
02   <area_series>
03     <line enabled="true" color="DarkColor(%Color)" thickness="2" opacity="1" />
04     <fill color="%Color" opacity="0.5" />
05   </area_series>
01{
02  areaSeries: {
03    line: {
04      enabled: true,
05      color: "DarkColor(%Color)",
06      thickness: 2,
07      opacity: 1
08    },
09    fill: {
10      color: "%Color",
11      opacity: 0.5
12    }
13  }
14}

As you can see %Color is used to configure fill and line, but for line color is transformed: DarkColor(%Color), to make border distinct.

Live sample below shows to Area series, two of them use settings from defaults section and the third one uses personal settings with static colors defined:

Live Sample:  Series - Using Dynamic and Static Colors

to top

Setting Name

You can set the name of the series using <name> subnode. Sample XML below shows this:

XML/JSON Syntax
Plain code
01 <chart>
02   <series_list>
03     <series type="Line" color="#2289FE" data_provider="dp2">
04       <name><![CDATA[Series A]]></name>
05     </series>
06   </series_list>
07 </chart>
01{
02  seriesList: [
03    {
04      type: "Line",
05      color: "#2289FE",
06      dataProvider: "dp2",
07      name: "Series A"
08    }
09  ]
10}

to top

Legend Element

For each series you can define its element in legend. This element contains the settings for the formatting string of the text in legend that represents the series. Configuration of such elements is described in Legend: Series Labels article.

to top

Tooltips

You can either use global tooltip settings or create personal tooltips for each series. See detailed description in Tooltips tutorial.

to top

Custom Attributes

For each series you can define a set of custom attributes that can hold any additional data about the series. These attributes can be used in legend, tooltips and passed to external event handlers.

Sample XML to define series custom attributes:

XML/JSON Syntax
Plain code
01 <chart>
02   <series_list>
03     <series type="Line" color="#0066DD" data_provider="dp1">
04       <attributes>
05         <attr name="ShortName"><![CDATA[MSFT]]></attr>
06         <attr name="LongName"><![CDATA[Microsoft Corparation]]></attr>
07         <attr name="StockSymbol"><![CDATA[NASDAQ:MSFT]]></attr>
08       </attributes>
09     </series>
10     <series type="Line" color="#FF12EE" data_provider="dp2">
11       <attributes>
12         <attr name="ShortName"><![CDATA[ORCL]]></attr>
13         <attr name="LongName"><![CDATA[Oracle Corparation]]></attr>
14         <attr name="StockSymbol"><![CDATA[NASDAQ:ORCL]]></attr>
15       </attributes>
16     </series>
17   </series_list>
18 </chart>
01{
02  seriesList: [
03    {
04      type: "Line",
05      color: "#0066DD",
06      dataProvider: "dp1",
07      attributes: {
08        ShortName: "MSFT",
09        LongName: "Microsoft Corparation",
10        StockSymbol: "NASDAQ:MSFT"
11      }
12    },
13    {
14      type: "Line",
15      color: "#FF12EE",
16      dataProvider: "dp2",
17      attributes: {
18        ShortName: "ORCL",
19        LongName: "Oracle Corparation",
20        StockSymbol: "NASDAQ:ORCL"
21      }
22    }
23  ]
24}

Samples of using custom attributes can be found at:

to top

Markers

Series of any type can show point markers of different shape and color.

Marker can be in to states "Normal" and "Hover". "Hover" is shown when user hover over the respective value on X-Axis, in all other cases marker is shown as "Normal".

Illustration below shows what is marker in Hover and in Normal states:

XML for tuning markers for the given series looks like that:

XML/JSON Syntax
Plain code
01 <series type="Line" data_provider="dp1" color="#005ECB">
02   <name><![CDATA[IBM]]></name>
03   <marker enabled="true" type="Circle">
04     <states>
05       <normal enabled="true" size="6">
06         <fill enabled="true" type="Solid" color="#FFFFFF" opacity="1" />
07         <border enabled="true" color="DarkColor(%Color)" thickness="1" opacity="1" />
08       </normal>
09       <hover enabled="true" size="10">
10         <fill enabled="true" type="Solid" color="#FFFFFF" opacity="1" />
11         <border enabled="true" color="DarkColor(%Color)" thickness="3" opacity="1" />
12       </hover>
13     </states>
14   </marker>
15 </series>
01{
02  type: "Line",
03  dataProvider: "dp1",
04  color: "#005ECB",
05  name: "IBM",
06  marker: {
07    enabled: true,
08    type: "Circle",
09    states: {
10      normal: {
11        enabled: true,
12        size: 6,
13        fill: {
14          enabled: true,
15          type: "Solid",
16          color: "#FFFFFF",
17          opacity: 1
18        },
19        border: {
20          enabled: true,
21          color: "DarkColor(%Color)",
22          thickness: 1,
23          opacity: 1
24        }
25      },
26      hover: {
27        enabled: true,
28        size: 10,
29        fill: {
30          enabled: true,
31          type: "Solid",
32          color: "#FFFFFF",
33          opacity: 1
34        },
35        border: {
36          enabled: true,
37          color: "DarkColor(%Color)",
38          thickness: 3,
39          opacity: 1
40        }
41      }
42    }
43  }
44}

As you can see all settings are done in <marker> node. This node should be placed in the settings block of the given series.

to top

Turning On / Off and States

To turn markers on or off enabled attribute of <marker> node is used. By default markers are enabled for all series types. To turn it off set: <marker enabled="false"/>.

Also, you can disable markers for the certain state. By default markers are turned on in "Hover" state, and turned off in "Normal" state. Turning states on and off can be done in enabled attribute of <hover> and <normal>. See sample XML below:

XML/JSON Syntax
Plain code
01 <marker enabled="true">
02   <states>
03     <normal enabled="true" />
04     <hover enabled="true" />
05   </states>
06 </marker>
01{
02  enabled: true,
03  states: {
04    normal: {
05      enabled: true
06    },
07    hover: {
08      enabled: true
09    }
10  }
11}

to top

Marker Type

Marker type defines a shape of the marker and is set using type attribute of <marker> node. Table below lists and shows all possible marker types:

  Type
Circle
Square
Diamond
Cross
DiagonalCross
HLine
VLine
Star4
Star5
Star6
Star7
TriangleUp
TriangleDown

to top

Marker Size

The size of the marker (in pixels) is set for each state using size attribute in <normal> and <hover> nodes.

Sample XML to define marker size in different states:

XML/JSON Syntax
Plain code
01 <marker enabled="true" type="Circle">
02   <states>
03     <normal enabled="true" size="10" />
04     <hover enabled="true" size="15" />
05   </states>
06 </marker>
01{
02  enabled: true,
03  type: "Circle",
04  states: {
05    normal: {
06      enabled: true,
07      size: 10
08    },
09    hover: {
10      enabled: true,
11      size: 15
12    }
13  }
14}

As you can see marker has the size of 10 pixels in "Normal" state, and 15 - in "Hover". If you want size to be the same in both states - set it in <marker> node, for example: <marker type="Circle" size="13">.

to top

Marker Fill and Border

You can change marker fill and border. Fill and border are configured in <fill> and <border> nodes for each marker state. When you define the color for them you can use %Color token (see more in Setting Color and using %Color token ).

Sample XML to configure fill and border in different states:

XML/JSON Syntax
Plain code
01 <marker type="Circle">
02   <states>
03     <normal enabled="true" size="6">
04       <fill type="Solid" color="#FFFFFF" opacity="1" />
05       <border enabled="true" color="%Color" thickness="2" opacity="1" />
06     </normal>
07     <hover enabled="true" size="10">
08       <fill type="Solid" color="Yellow" opacity="1" />
09       <border enabled="true" color="DarkColor(%Color)" thickness="3" opacity="1" />
10     </hover>
11   </states>
12 </marker>
01{
02  type: "Circle",
03  states: {
04    normal: {
05      enabled: true,
06      size: 6,
07      fill: {
08        type: "Solid",
09        color: "#FFFFFF",
10        opacity: 1
11      },
12      border: {
13        enabled: true,
14        color: "%Color",
15        thickness: 2,
16        opacity: 1
17      }
18    },
19    hover: {
20      enabled: true,
21      size: 10,
22      fill: {
23        type: "Solid",
24        color: "Yellow",
25        opacity: 1
26      },
27      border: {
28        enabled: true,
29        color: "DarkColor(%Color)",
30        thickness: 3,
31        opacity: 1
32      }
33    }
34  }
35}

to top

Marker Sample

Live sample below shows marker settings.

Live Sample:  Series - Using Markers

to top

Range Types Specifics

Series of RangeBar, RangeArea and RangeSplineArea types have two markers instead of one (for high and low values).

Specifics is described in the following articles:

to top

Value Highlighter

The AnyChart Stock component offers two additional elements for highlighting values under the mouse pointer. Those are Date Highlighter, which is an X-axis customization, and Value Highlighter, which is a customization of a specific series. These two elements together form an element known to end-users as Crosshair.

You can also be interested in Y-Axis value highlighter, which enables user to see the value he hovers on the plot without reference to series value(s).

Value Highlighter is a horizontal line drawn through the entire plot area. The line is drawn through the point pinned by the mouse pointer. Besides the line, Value Highlighter can contain one or more labels, which could display the current value or any static text.

The illustration below demonstrates the elements Value Highlighter consists of:

This section gives a brief coverage on configuring the element. For further details on all available functions, please refer to XML Reference.

Enabling and Customizing Line

By default, Value Highlighter is disabled. The element can be enabled and customized only for a specific data series.

Below is the XML syntax for enabling and customizing the line:

XML/JSON Syntax
Plain code
01 <chart>
02   <series_list>
03     <series type="Line" data_provider="dp1" color="DarkRed">
04       <value_highlighter enabled="true">
05         <line color="#AA1010" thickness="1" opacity="1" />
06       </value_highlighter>
07     </series>
08   </series_list>
09 </chart>
01{
02  seriesList: [
03    {
04      type: "Line",
05      dataProvider: "dp1",
06      color: "DarkRed",
07      valueHighlighter: {
08        enabled: true,
09        line: {
10          color: "#AA1010",
11          thickness: 1,
12          opacity: 1
13        }
14      }
15    }
16  ]
17}

As you can see on the listing, all the settings are provided in the <value_highlighter> node.

The live sample below demonstrates the use of two series with Value Highlighter enabled for one of them:

Live Sample:  Series Value Highlighter - Enabling and Line Settings

Detailed information on customizing the value highlighter's line is available in XML Reference.

to top

Adding Value Label

You can add a single or multiple labels to Value Highlighter. A label can display the value of the point, static text or a combination of the value and static text. By default, Value Highlighter does not have any predefined labels.

Below is the XML syntax for setting up a label to be positioned at the right within the plot area. For the sake of better readability, the label has a background:

XML/JSON Syntax
Plain code
01 <chart>
02   <series_list>
03     <series type="Line" data_provider="dp1" color="#005ECB">
04       <name><![CDATA[^IXIC:]]></name>
05       <value_highlighter enabled="true">
06         <line thickness="1" color="#777777" dashed="false" opacity="1" />
07         <labels>
08           <label anchor="Right" x_padding="5" y_padding="0" valign="Center" halign="Left">
09             <format><![CDATA[{%Value}{numDecimals:2}]]></format>
10             <font family="Tahoma" size="9" bold="false" color="White" />
11             <background enabled="true">
12               <fill enabled="true" type="Solid" color="#005ECB" opacity="1" />
13               <border enabled="false" color="#CBAF87" />
14               <corners type="Rounded" all="3" />
15               <inside_margin left="3" right="3" />
16             </background>
17           </label>
18         </labels>
19       </value_highlighter>
20     </series>
21   </series_list>
22 </chart>
01{
02  seriesList: [
03    {
04      type: "Line",
05      dataProvider: "dp1",
06      color: "#005ECB",
07      name: "^IXIC:",
08      valueHighlighter: {
09        enabled: true,
10        line: {
11          thickness: 1,
12          color: "#777777",
13          dashed: false,
14          opacity: 1
15        },
16        labels: [
17          {
18            anchor: "Right",
19            xPadding: 5,
20            yPadding: 0,
21            valign: "Center",
22            halign: "Left",
23            format: "{%Value}{numDecimals:2}",
24            font: {
25              family: "Tahoma",
26              size: 9,
27              bold: false,
28              color: "White"
29            },
30            background: {
31              enabled: true,
32              fill: {
33                enabled: true,
34                type: "Solid",
35                color: "#005ECB",
36                opacity: 1
37              },
38              border: {
39                enabled: false,
40                color: "#CBAF87"
41              },
42              corners: {
43                type: "Rounded",
44                all: 3
45              },
46              insideMargin: {
47                left: 3,
48                right: 3
49              }
50            }
51          }
52        ]
53      }
54    }
55  ]
56}

To have the label display a value, insert the {%Value} token into the text formatting string. Below is the XML syntax for inserting the token into the formatting string:

XML/JSON Syntax
Plain code
01 <label>
02   <format><![CDATA[{%Value}{numDecimals:2}]]></format>
03 </label>
01{
02  format: "{%Value}{numDecimals:2}"
03}

The {%Value} token is numeric, so you can customize its appearance. For more information on customizing the numeric token parameters, please refer to Numbers Formatting.

The live sample below demonstrates adding labels to different series; one of them uses two labels.

Live Sample:  Series Value Highlighter - Using Label

As you can see from the sample, the lower chart uses a data series of the Candlestick type. For Candlestick and OHLC series, Value Highlighter always appears in the value of the Close field; the value in the captions, returned by the {%Value} token, also matches the value of the Close field.

This section covers only the basic principles of adding and using labels. For the comprehensive coverage, please refer to XML Reference.

to top

Customizing for the RangeBar, RangeArea and RangeSplineArea Series Types

It has been told above that Value Highlighter is configured in the section; however, the exceptions are the RangeBar, RangeArea and RangeSplineArea types series, as they display two values instead of one, and Value Highlighter can be used for each of them.

The XML syntax below gives a simplified demonstration of where Value Highlighters are configured for the high and low values by the example of the Range Area type:

XML/JSON Syntax
Plain code
01 <chart>
02   <series_list>
03     <series type="RangeArea">
04       <range_area_series>
05         <high>
06           <value_highlighter />
07         </high>
08         <low>
09           <value_highlighter />
10         </low>
11       </range_area_series>
12     </series>
13   </series_list>
14 </chart>
01{
02  seriesList: [
03    {
04      type: "RangeArea",
05      rangeAreaSeries: {
06        high: {
07          valueHighlighter: {}
08        },
09        low: {
10          valueHighlighter: {}
11        }
12      }
13    }
14  ]
15}

With range-based series, Value Highlighters function the same way as they do with series of other types; thus, you can easily use the entire range of their functions and settings.

This live sample demonstrates the use of the RangeSplineArea and RangeBar type series with Value Highlighter:

Live Sample:  Series Value Highlighter for Range Based Series Types

to top

Series binding to extra Y-Axis

AnyChart Stock allows to use extra Y-Axes. The main purpose of extra axes is showing two or more series in different scales, for example when series ranges differs greatly or series are measured in different units.

By default all series are bound to the primary Y-Axis. To bind series to alternative axis you should specify axis identifier, like shown in 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   <settings>
04     <charts>
05       <chart>
06         <value_axes>
07           <primary />
08           <extra>
09             <axis id="extra1" />
10             <axis id="extra2" />
11           </extra>
12         </value_axes>
13         <series_list>
14           <series />
15           <series axis="extra1" />
16           <series axis="extra2" />
17         </series_list>
18       </chart>
19     </charts>
20   </settings>
21 </stock>
01{
02  settings: {
03    charts: [
04      {
05        valueAxes: {
06          primary: {},
07          extra: [
08            {
09              id: "extra1"
10            },
11            {
12              id: "extra2"
13            }
14          ]
15        },
16        seriesList: [
17          {},
18          {
19            axis: "extra1"
20          },
21          {
22            axis: "extra2"
23          }
24        ]
25      }
26    ]
27  }
28}

As you can see there are to extra axes: extra1 and extra2, and three series - one bound to primary Y-Axis, and two other series - to extra axes. Binding is done using axis attribute in <series> node, like that: <series axis="extra5"/>.

Live sample below shows binding series to axes:

Live Sample:  Binding Series to the Axis

Extra axes are described in details in "Adding and using Extra Axes" section of Y-Axes Settings Tutorial .

to top

Series Z-Index

By default all series are drawn in the order they are defined in a configuration.

You can change ordering using z_index attribute in <series> that specifies the display order of a series on a certain chart panel. A series with a greater z-index is always in front of a series with a lower z-index. It works for regular series as well as for series that are used to visualize technical indicators.

Sample syntax:

XML/JSON Syntax
Plain code
01 <chart>
02   <series_list>
03     <series type="Line" data_provider="dp1" color="#005ECB" z_index="2">
04       <name><![CDATA[Series A]]></name>
05     </series>
06     <series type="Line" data_provider="dp2" color="#DD5E5E" z_index="1">
07       <name><![CDATA[Series A]]></name>
08     </series>
09   </series_list>
10 </chart>
01{
02  seriesList: [
03    {
04      type: "Line",
05      dataProvider: "dp1",
06      color: "#005ECB",
07      zIndex: 2,
08      name: "Series A"
09    },
10    {
11      type: "Line",
12      dataProvider: "dp2",
13      color: "#DD5E5E",
14      zIndex: 1,
15      name: "Series A"
16    }
17  ]
18}

Live sample below demonstrates how to change display order for two series. Top chart demonstrates default order, on the bottom chart Bar series is put behind the line.

Live Sample:  Series ordering

Live sample below demonstrates how to change display order for candlestick series and BBands indicator. Top chart demonstrates default order, on the bottom chart BBands indicator is put behind the candlestick series:

Live Sample:  Candlestick series and BBands indicator ordering

Live sample below demonstrates how to change display order of series for MACD indicator. Top chart demonstrates default order, on the bottom chart histogram series is put behind lines:

Live Sample:  Technical Indicator - Series Ordering

to top

Defaults Section

There is a special section to set default values in AnyChart Stock component XML: <series_settings_defaults>, where you can define marker and value highlighter settings for all series of the given type in one place, instead of setting them for each series individually.

For example, to configure line thickness in one chart for all series of Line, Spline, StepLine and Stick types just set:

XML/JSON Syntax
Plain code
01 <chart>
03     <line_series thickness="2" />
05 </chart>
01{
03    lineSeries: {
04      thickness: 2
05    }
06  }
07}

Live sample below has three series: of Line, Spline and StepLine types. All series use marker and value highlighter settings defined in <line_series/> node :

Live Sample:  Series - Using Defaults Sections

Default for other types work in the same way. Table below shows what sections in XML configure certain series types:

Series Type Node's Name
Line, Spline, StepLine, Stick <line_series>
Area, SplineArea, StepLineArea <area_series>
Bar <bar_series>
RangeArea, RangeSplineArea <range_area_series>
RangeBar <range_bar_series>
Candlestick <candlestick_series>
OHLC <ohlc_series>
Marker <marker_series>

Note that there is another way to define defaults:

to top