Vertical Line

Overview

The Vertical Line annotation allows to add a vertical line to a chart.

This article explains how to add a Vertical Line and configure its basic and visual settings. You can find more settings and other useful information in the articles describing annotations in general:

Basic Settings

To add a Vertical Line annotation to a chart, call the verticalLine() method of the annotations() object.

Next, use the xAnchor(), method to set the timestamp that determines the position of the vertical line. Usually, the most convenient way to do this is object notation:

// create a stock chart
chart = anychart.stock();

// create a plot on the chart
var plot = chart.plot(0);

// access the annotations() object of the plot to work with annotations
var controller = plot.annotations();

// create a Vertical Line annotation
controller.verticalLine({
    xAnchor: "2007-09-23"
});

This is how it looks like:

JsFiddle Playground

Appearance

The appearance settings of a Vertical Line annotation can be configured in three states: normal, hover, and selected. Use the following methods:

Combine them with these methods:

You can also use object notation to specify the settings.

In the sample below, there are two Vertical Line annotations with some of the visual settings configured (by using an object in the first case and methods in the second):

// create the first Vertical Line annotation and configure its visual settings
var verticalLine1 = controller.verticalLine({
    xAnchor: "2007-09-23",
    hovered: {stroke: "2 #FF0000"},
    selected: {stroke: "5 #FF0000"}
});

// create the second Vertical Line annotation
var verticalLine2 = controller.verticalLine();

// set the position of the second annotation
verticalLine2.xAnchor("2005-05-22");
 
// configure the visual settings of the second annotation
verticalLine2.normal().stroke("#2196F3", 3, "10 2");

JsFiddle Playground