Legend: Title and Date-Time Labels

Overview

Legend has two text elements that allow to show date ane time of the hovered point or the range of data displayed, they are Title and Date-Time Label. Also, these elements can show simple static text.

Illustration below highlights them on a sample chart:

Title is the label on the left, by default it shows the date if the hovered point, if the mouse doesn't hover any point the title shows the end of the displayed range.

Date-Time Label is the label on the right, by default it displays the selected range.

Title and Date-Time lable are similar - the only difference is their place inside the legend. They are configured in <title> and <date_time_label> subnodes of <legend> node for each chart.

Sample XML:

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         <legend>
07           <title />
08           <date_time />
09         </legend>
10       </chart>
11     </charts>
12   </settings>
13 </stock>
01{
02  settings: {
03    charts: [
04      {
05        legend: {
06          title: {},
07          dateTime: {}
08        }
09      }
10    ]
11  }
12}

to top

Turning On / Off

By default both elements are enabled, to disable them set enabled attribute to false.

Sample XML to turn both elements off:

XML/JSON Syntax
Plain code
01 <chart>
02   <legend>
03     <title enabled="false" />
04     <date_time enabled="false" />
05   </legend>
06 </chart>
01{
02  legend: {
03    title: {
04      enabled: false
05    },
06    dateTime: {
07      enabled: false
08    }
09  }
10}

Live sample below shows two charts - with Date-Time Label disabled for the first one and with Title disabled for the second:

Live Sample:  Legend - Enable and Disable Title

to top

States

Both labels can show different text in two states:

Mouse Over - when user hovers some data point.

Mouse Out - when no point is hovered.

For each state the following options can be configured:

XML below shows these settings:

XML/JSON Syntax
Plain code
01 <legend>
02   <title>
03     <focus_settings>
04       <mouse_over>
05         <font />
06         <format><![CDATA[Mouse-Over Text]]></format>
07       </mouse_over>
08       <mouse_out>
09         <font />
10         <format><![CDATA[Mouse-Out Text]]></format>
11       </mouse_out>
12     </focus_settings>
13   </title>
14   <date_time>
15     <focus_settings>
16       <mouse_over>
17         <font />
18         <format><![CDATA[Mouse-Over Text]]></format>
19       </mouse_over>
20       <mouse_out>
21         <font />
22         <format><![CDATA[Mouse-Out Text]]></format>
23       </mouse_out>
24     </focus_settings>
25   </date_time>
26 </legend>
01{
02  title: {
03    focusSettings: {
04      mouseOver: {
05        font: {},
06        format: "Mouse-Over Text"
07      },
08      mouseOut: {
09        font: {},
10        format: "Mouse-Out Text"
11      }
12    }
13  },
14  dateTime: {
15    focusSettings: {
16      mouseOver: {
17        font: {},
18        format: "Mouse-Over Text"
19      },
20      mouseOut: {
21        font: {},
22        format: "Mouse-Out Text"
23      }
24    }
25  }
26}

to top

Font settings

To configure the font for the labels typical <font> node is used, which is described in details in Font Configuration article.

Sample XML for setting font for both elements in different states:

XML/JSON Syntax
Plain code
01 <legend enabled="true">
02   <title enabled="true">
03     <focus_settings>
04       <mouse_over>
05         <font family="Verdana" size="12" bold="true" color="Green" />
06       </mouse_over>
07       <mouse_out>
08         <font family="Verdana" size="12" bold="false" color="DarkRed" />
09       </mouse_out>
10     </focus_settings>
11   </title>
12   <date_time enabled="true">
13     <focus_settings>
14       <mouse_over>
15         <font family="Times New Roman" size="12" bold="true" color="Blue" />
16       </mouse_over>
17       <mouse_out>
18         <font family="Arial" size="12" bold="false" color="#5577F0" />
19       </mouse_out>
20     </focus_settings>
21   </date_time>
22 </legend>
01{
02  enabled: true,
03  title: {
04    enabled: true,
05    focusSettings: {
06      mouseOver: {
07        font: {
08          family: "Verdana",
09          size: 12,
10          bold: true,
11          color: "Green"
12        }
13      },
14      mouseOut: {
15        font: {
16          family: "Verdana",
17          size: 12,
18          bold: false,
19          color: "DarkRed"
20        }
21      }
22    }
23  },
24  dateTime: {
25    enabled: true,
26    focusSettings: {
27      mouseOver: {
28        font: {
29          family: "Times New Roman",
30          size: 12,
31          bold: true,
32          color: "Blue"
33        }
34      },
35      mouseOut: {
36        font: {
37          family: "Arial",
38          size: 12,
39          bold: false,
40          color: "#5577F0"
41        }
42      }
43    }
44  }
45}

Live sample below shows settings given above:

Live Sample:  Legend - Title Font Settings

to top

Text Formatting

To define text to be displayed in Title and Date-Time Label you need to set formatting string for both states. You can either use static text and/or use {%Date} token.

To define formatting string <format> subnode of <mouse_over> and <mouse_out> nodes is used. Sample XML for setting Title formatting follows:

XML/JSON Syntax
Plain code
01 <legend>
02   <title>
03     <focus_settings>
04       <mouse_over>
05         <format><![CDATA[Mouse-Over Text]]></format>
06       </mouse_over>
07       <mouse_out>
08         <format><![CDATA[Mouse-Out Text]]></format>
09       </mouse_out>
10     </focus_settings>
11   </title>
12 </legend>
01{
02  title: {
03    focusSettings: {
04      mouseOver: {
05        format: "Mouse-Over Text"
06      },
07      mouseOut: {
08        format: "Mouse-Out Text"
09      }
10    }
11  }
12}

 

Static Text

To show static text in Title or Date-Time Label just type it into <format> node, for example: <format>MSFT Corp. 2005-2008: </format>. To use special symbols please use CDATA block

XML below shows how to set static text for both elemenet. Note that you should set format for both states if you want this text to be the same no matter what happens:

XML/JSON Syntax
Plain code
01 <legend>
02   <title>
03     <focus_settings>
04       <mouse_over>
05         <format><![CDATA[Symbols: ]]></format>
06       </mouse_over>
07       <mouse_out>
08         <format><![CDATA[Symbols: ]]></format>
09       </mouse_out>
10     </focus_settings>
11   </title>
12   <date_time>
13     <focus_settings>
14       <mouse_over>
15         <format><![CDATA[© 2009]]></format>
16       </mouse_over>
17       <mouse_out>
18         <format><![CDATA[© 2009]]></format>
19       </mouse_out>
20     </focus_settings>
21     <font bold="true" />
22   </date_time>
23 </legend>
01{
02  title: {
03    focusSettings: {
04      mouseOver: {
05        format: "Symbols: "
06      },
07      mouseOut: {
08        format: "Symbols: "
09      }
10    }
11  },
12  dateTime: {
13    focusSettings: {
14      mouseOver: {
15        format: "© 2009"
16      },
17      mouseOut: {
18        format: "© 2009"
19      }
20    },
21    font: {
22      bold: true
23    }
24  }
25}

Live sample below shows these elements with static text in them:

Live Sample:  Legend - Formatting with Static Text

to top

Date Time Tokens

Instead or in addition to static text you can use {%Date} token, which provides you an ability to show some dynamic chart information, which reflects current chart state.

To show the date you just need to put {%Date} into the formatting, where needed. For example: <format>Date: {%Date.*}</format>, with one of the token properties listed below specified instead of "*".

Table below list all token properties:

Property Description
{%Date.Current} Date time of the hovered point.
{%Date.First} Date time of the first point in the dataset.
{%Date.Last} Date time of the last point in the dataset.
{%Date.FirstVisible} Date time of the first point in the range shown.
{%Date.LastVisible} Date time of the last point in the range shown.

Illustration below gives visible explanation for each property of the token:

You can use {%Date} several times in one formatting string - with different properties. Sample XML below shows how to use token in formatting string of Title and Date-Time Label:

XML/JSON Syntax
Plain code
01 <legend>
02   <title>
03     <focus_settings>
04       <mouse_over>
05         <format><![CDATA[Mouse Over - {%Date.Current}{"%MMMM %dd, %yyyy"}: ]]></format>
06       </mouse_over>
07       <mouse_out>
08         <format><![CDATA[Mouse Out - {%Date.LastVisible}{"%yyyy-%mm-%dd"}: ]]></format>
09       </mouse_out>
10     </focus_settings>
11   </title>
12   <date_time>
13     <focus_settings>
14       <mouse_over>
15         <format><![CDATA[Current Date: {%Date.Current}{"%yyyy-%mm-%dd; %hh:%mm %tt"}]]></format>
16       </mouse_over>
17       <mouse_out>
18         <format><![CDATA[Visible Range: {%Date.FirstVisible}{"%yyyy-%mm-%dd"} - {%Date.LastVisible}{"%yyyy-%mm-%dd"}]]></format>
19       </mouse_out>
20     </focus_settings>
21   </date_time>
22 </legend>
01{
02  title: {
03    focusSettings: {
04      mouseOver: {
05        format: "Mouse Over - {%Date.Current}{\"%MMMM %dd, %yyyy\"}: "
06      },
07      mouseOut: {
08        format: "Mouse Out - {%Date.LastVisible}{\"%yyyy-%mm-%dd\"}: "
09      }
10    }
11  },
12  dateTime: {
13    focusSettings: {
14      mouseOver: {
15        format: "Current Date: {%Date.Current}{\"%yyyy-%mm-%dd; %hh:%mm %tt\"}"
16      },
17      mouseOut: {
18        format: "Visible Range: {%Date.FirstVisible}{\"%yyyy-%mm-%dd\"} - {%Date.LastVisible}{\"%yyyy-%mm-%dd\"}"
19      }
20    }
21  }
22}

You can see that you can define date time format when you use the {%Date} token, for example: {%Date.Current}{"%MMMM %dd, %yyyy"}, "%MMMM %dd, %yyyy" stiring in braces that follows the token defines format for timestamp.

You can define any format for the value using these patterns. Date Time formatting is described in details in Date-Time Formatting article .

Live sample below shows how different properties of {%Date} token can be used:

Live Sample:  Legend - Formatting Using Tokens

to top

Title Width

When you use {%Date} token in Title - the width of the label varies depending on the current value of the date, this may lead to "jumping" series labels to the right of the title. TO avoid this you can set the fixed width for the title.

Sample XML to define Title width:

XML/JSON Syntax
Plain code
01 <chart>
02   <legend>
03     <title width="120" />
04   </legend>
05 </chart>
01{
02  legend: {
03    title: {
04      width: 120
05    }
06  }
07}

Sample below shows a chart with a Title showing current hovered date while the mouse is over the chart. That makes labels "jump" on the chart where Title width isn't set (the second chart), and makes labels stay on their places where Title width is set (the first chart):

Live Sample:  Legend - Title with Fixed Width

to top