Fibonacci Time Zones

Overview

The Fibonacci Time Zones annotation allows you to add Fibonacci time zones to a chart.

This article explains how to add a Fibonacci Time Zones 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 Fibonacci Time Zones annotation to a chart, call the fibonacciTimezones() method of the annotations() object.

Next, use the xAnchor(), valueAnchor(), secondXAnchor(), and secondValueAnchor() methods to set 2 points that determine the position of the Fibonacci time zones. 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 Fibonacci Time Zones annotation
controller.fibonacciTimezones({
    xAnchor: "2006-07-30",
    valueAnchor: 17.24,
    secondXAnchor: "2007-01-07",
    secondValueAnchor: 28.92
});

This is how it looks like:

Playground

Levels

You can set the levels of a Fibonacci Time Zones annotation by using the levels() method and passing an array of values as a parameter:

// create a Fibonacci Time Zones annotation
controller.fibonacciTimezones({
    xAnchor: "2006-07-30",
    valueAnchor: 17.24,
    secondXAnchor: "2007-01-07",
    secondValueAnchor: 28.92,
    levels: [0,0.4,1]
});

Playground

Appearance

The appearance settings of a Fibonacci Time Zones 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 Fibonacci Timezones annotations with some of the visual settings configured (by using an object in the first case and methods in the second):

// create the first Fibonacci Time Zones annotation and configure its visual settings
var fibonacciTimezones1 = controller.fibonacciTimezones({
    xAnchor: "2006-07-30",
    valueAnchor: 17.24,
    secondXAnchor: "2007-01-07",
    secondValueAnchor: 28.92,
    normal: {
        labels: {fontColor: "#ff0000"}
    },
    hovered: {
        stroke: "2 #ff0000",
        trend: "2 #0000ff",
        labels: {fontColor: "#ff0000"}
    },
    selected: {
        stroke: "4 #ff0000", 
        trend: "4 #0000ff",
        labels: {fontColor: "#ff0000"}
    }     
});

// create the second Fibonacci Time Zones annotation
var fibonacciTimezones2 = controller.fibonacciTimezones();

// set the position of the second annotation
fibonacciTimezones2.xAnchor("2004-01-11");
fibonacciTimezones2.valueAnchor(29.13);
fibonacciTimezones2.secondXAnchor("2004-06-06");
fibonacciTimezones2.secondValueAnchor(23.82);
 
// configure the visual settings of the second annotation
fibonacciTimezones2.normal().labels().fontColor("#00b300");
fibonacciTimezones2.normal().stroke("#006600", 1, "10 2");
fibonacciTimezones2.hovered().stroke("#00b300", 2, "10 2");
fibonacciTimezones2.selected().stroke("#00b300", 4, "10 2");

Playground

To configure the visual settings of a certain level, use the normal(), selected(), and hovered() methods combined with stroke() and a function as a parameter. In this function, get level values from the context:

// create a Fibonacci Time Zones annotation
controller.fibonacciTimezones({
    xAnchor: "2006-07-30",
    valueAnchor: 17.24,
    secondXAnchor: "2007-01-07",
    secondValueAnchor: 28.92,
    normal: {stroke: colorLevels},
    hovered: {stroke: colorLevels},
    selected: {stroke: colorLevels}
});

function colorLevels(){
  if (this.level!==undefined) {
    switch (this.level) {
        case 1:
            return "red";
            break;
        case 2:
            return {color: "blue", dash: "2 2"};
            break;
        default:
                return "black";
    }
  }
};

Playground

Labels

You can change the text of Fibonacci Time Zones labels with the help of text formatters.

Combine the labels() and format() methods with the following tokens:

  • {%level} (shown by default)
  • {%levelValue}
    // create a Fibonacci Time Zones annotation
    var fibonacciTimezones = controller.fibonacciTimezones({
        xAnchor: "2004-08-08",
        valueAnchor: 17.9,
        secondXAnchor: "2006-10-08",
        secondValueAnchor: 24.5
    });
    
    // configure the annotation labels
    fibonacciTimezones.labels().format("{%level} ({%levelValue})");
    

Playground

Instead of tokens, you can also use formatting functions and the following fields:

  • level (shown by default)
  • levelValue
    // configure the annotation labels
    fibonacciTimezones.labels().format(function() {
      // convert the level value (timestamp) to a string (date)
      var levelValue = anychart.format.dateTime(this.levelValue);
      switch (this.level) {
          case 0:
              return this.level + " (" + levelValue + ")";
              break;
          default:
                  return this.level;
      }
    });
    

Playground