Annotated Timeline

Overview

An interactive time series line chart with optional annotations.

The annotated timeline now automatically uses Annotation Charts instead.

Example

<html>
  <head>
    <script type='text/javascript' src='https://www.gstatic.com/charts/loader.js'></script>
    <script type='text/javascript'>
      google.charts.load('current', {'packages':['annotatedtimeline']});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('date', 'Date');
        data.addColumn('number', 'Sold Pencils');
        data.addColumn('string', 'title1');
        data.addColumn('string', 'text1');
        data.addColumn('number', 'Sold Pens');
        data.addColumn('string', 'title2');
        data.addColumn('string', 'text2');
        data.addRows([
          [new Date(2008, 1 ,1), 30000, undefined, undefined, 40645, undefined, undefined],
          [new Date(2008, 1 ,2), 14045, undefined, undefined, 20374, undefined, undefined],
          [new Date(2008, 1 ,3), 55022, undefined, undefined, 50766, undefined, undefined],
          [new Date(2008, 1 ,4), 75284, undefined, undefined, 14334, 'Out of Stock','Ran out of stock on pens at 4pm'],
          [new Date(2008, 1 ,5), 41476, 'Bought Pens','Bought 200k pens', 66467, undefined, undefined],
          [new Date(2008, 1 ,6), 33322, undefined, undefined, 39463, undefined, undefined]
        ]);

        var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
        chart.draw(data, {displayAnnotations: true});
      }
    </script>
  </head>

  <body>
    // Note how you must specify the size of the container element explicitly!
    <div id='chart_div' style='width: 700px; height: 240px;'></div>
  </body>
</html>

Important: To use this visualization, you must specify the height and width of the container element explicitly on your page. So, for example: <div id="chart_div" style="width:400; height:250"></div>.

Loading

The google.charts.load package name is "annotatedtimeline"

  google.charts.load("current", {packages: ['annotatedtimeline']});

The visualization's class name is google.visualization.AnnotatedTimeLine

  var visualization = new google.visualization.AnnotatedTimeLine(container);

Data Format

You can display one or more lines on your chart. Each row represents an X position on the chart--that is, a specific time; each line is described by a set of one to three columns.

  • The first column is of type date or datetime, and specifies the X value of the point on the chart. If this column is of type date (and not datetime) then the smallest time resolution on the X axis will be one day.
  • Each data line is then described by a set of one to three additional columns as described here:
    • Y value - [Required, Number] The first column in each set describes the value of the line at the corresponding time from the first column. The column label is displayed on the chart as the title of that line.
    • Annotation title - [Optional, String] If a string column follows the value column, and the displayAnnotations option is true, this column holds a short title describing this point. For instance, if this line represents temperature in Brazil, and this point is a very high number, the title could be "Hottest day on record".
    • Annotation text - [Optional string] If a second string column exists for this series, the cell value will be used as additional descriptive text for this point. You must set the option displayAnnotations to true to use this column. You can use HTML tags, if you set allowHtml to true; there is essentially no size limit, but note that excessively long entries might overflow the display section. You are not required to have this column even if you have an annotation title column for this point. The column label is not used by the chart. For example, if this were the hottest day on record point, you might say something like "Next closest day was 10 degrees cooler!".

Configuration Options

Name Type Default Description
allowHtml boolean false If set to true, any annotation text that includes HTML tags will be rendered as HTML.
allowRedraw boolean false

Enables a more efficient redrawing technique for the second and later calls to draw() on this visualization. It only redraws the chart area. To use this option, you must fulfill the following requirements:

  • allowRedraw must be true
  • displayAnnotations must be false (that is, you cannot show annotations)
  • you must pass in the same options and values (except for the allowRedraw and displayAnnotations) as in your first call to draw().
allValuesSuffix string none A suffix to be added to all values in the scales and the legend.
annotationsWidth number 25 The width (in percent) of the annotations area, out of the entire chart area. Must be a number in the range 5-80.
colors Array of strings Default colors The colors to use for the chart lines and labels. An array of strings. Each element is a string in a valid HTML color format. For example 'red' or '#00cc00'.
dateFormat string Either 'MMMM dd, yyyy' or 'HH:mm MMMM dd, yyyy', depending on the type of the first column (date, or datetime, respectively). The format used to display the date information in the top right corner. The format of this field is as specified by the java SimpleDateFormat class.
displayAnnotations boolean false If set to true, the chart will show annotations on top of selected values. When this option is set to true, after every numeric column, two optional annotation string columns can be added, one for the annotation title and one for the annotation text.
displayAnnotationsFilter boolean false If set to true, the chart will display a filter contol to filter annotations. Use this option when there are many annotations.
displayDateBarSeparator boolean true Whether to display a small bar separator ( | ) between the series values and the date in the legend, where true means yes.
displayExactValues boolean false Whether to display a shortened, rounded version of the values on the top of the graph, to save space; false indicates that it may. For example, if set to false, 56123.45 might be displayed as 56.12k.
displayLegendDots boolean true Whether to display dots next to the values in the legend text, where true means yes.
displayLegendValues boolean true Whether to display the highlighted values in the legend, where true means yes.
displayRangeSelector boolean true

Whether to show the zoom range selection area (the area at the bottom of the chart), where false means no.

The outline in the zoom selector is a log scale version of the last series in the chart, scaled to fit the height of the zoom selector.

displayZoomButtons boolean true Whether to show the zoom links ("1d 5d 1m" and so on), where false means no.
fill number 0 A number from 0—100 (inclusive) specifying the alpha of the fill below each line in the line graph. 100 means 100% opaque fill, 0 means no fill at all. The fill color is the same color as the line above it.
highlightDot string 'nearest'

Which dot on the series to highlight, and corresponding values to show in the legend. Select from one of these values:

  • 'nearest' - The values closest along the X axis to the mouse.
  • 'last' - The next set of values to the left of the mouse.
legendPosition string 'sameRow' Whether to put the colored legend on the same row with the zoom buttons and the date ('sameRow'), or on a new row ('newRow').
max number automatic The maximum value to show on the Y axis. If the maximum data point exceeds this value, this setting will be ignored, and the chart will be adjusted to show the next major tick mark above the maximum data point. This will take precedence over the Y axis maximum determined by scaleType.
min number automatic The minimum value to show on the Y axis. If the minimum data point is less than this value, this setting will be ignored, and the chart will be adjusted to show the next major tick mark below the minimum data point. This will take precedence over the Y axis minimum determined by scaleType.
numberFormats String, or a map of number:String pairs automatic

Specifies the number format patterns to be used to format the values at the top of the graph.

The patterns should be in the format as specified by the java DecimalFormat class.

  • If not specified, the default format pattern is used.
  • If a single string pattern is specified, it is used for all of the values.
  • If a map is specified, the keys are (zero-based) indexes of series, and the values are the patterns to be used to format the specified series.
    You are not required to include a format for every series on the chart; any unspecified series will use the default format.

If this option is specified, the displayExactValues option is ignored.

scaleColumns Array of numbers Automatic

Specifies which values to show on the Y axis tick marks in the graph. The default is to have a single scale on the right side, which applies to both series; but you can have different sides of the graph scaled to different series values.

This option takes an array of zero to three numbers specifying the (zero-based) index of the series to use as the scale value. Where these values are shown depends on how many values you include in your array:

  • If you specify an empty array, the chart will not show Y values next to the tick marks.
  • If you specify one value, the scale of the indicated series will be displayed on the right side of the chart only.
  • If you specify two values, a scale for the second series will be added to the right of the chart.
  • If you specify three values, a scale for the third series will be added to the middle of the chart.
  • Any values after the third in the array will be ignored.

When displaying more than one scale, it is advisable to set the scaleType option to either 'allfixed' or 'allmaximized'.

scaleType string 'fixed'

Sets the maximum and minimum values shown on the Y axis. The following options are available:

  • 'maximized' - The Y axis will span the minimum to the maximum values of the series. If you have more than one series, use allmaximized.
  • 'fixed' [default] - The Y axis varies, depending on the data values values:
    • If all values are >=0, the Y axis will span from zero to the maximum data value.
    • If all values are <=0, the Y axis will span from zero to the minimum data value.
    • If values are both positive and negative, the Y axis will range from the series maximum to the series minimum.

      For multiple series, use 'allfixed'.
  • 'allmaximized' - Same as 'maximized,' but used when multiple scales are displayed. Both charts will be maximized within the same scale, which means that one will be misrepresented against the Y axis, but hovering over each series will display it's true value.
  • 'allfixed' - Same as 'fixed,' but used when multiple scales are displayed. This setting adjusts each scale to the series to which it applies (use this in conjunction with scaleColumns).

If you specify the min and/or max options, they will take precedence over the minimum and maximum values determined by your scale type.

thickness number 0 A number from 0—10 (inclusive) specifying the thickness of the lines, where 0 is the thinnest.
wmode string 'window' The Window Mode (wmode) parameter for the Flash chart. Available values are: 'opaque', 'window' or 'transparent'.
zoomEndTime Date none Sets the end date/time of the selected zoom range.
zoomStartTime Date none Sets the start date/time of the selected zoom range.

Methods

Method Return Type Description
draw(data, options) none Draws the chart. You can speed up response time for the second and later calls to draw() by using the allowRedraw property.
getSelection() Array of selection elements Standard getSelection() implementation. Selected elements are cell elements. Only one cell can be selected at a time by the user.
getVisibleChartRange() An object with start and end properties Returns an object with start and end properties, which each one of them is a Date object, representing the current time selection.
hideDataColumns(columnIndexes) none Hides the specified data series from the chart. Accepts one parameter which can be a number or an array of numbers, in which 0 refers to the first data series, and so on.
setVisibleChartRange(start, end) none Sets the visible range (zoom) to the specified range. Accepts two parameters of type Date that represent the first and last times of the wanted selected visible range. Set start to null to include everything from the earliest date to end; set end to null to include everything from start to the last date.
showDataColumns(columnIndexes) none Shows the specified data series from the chart, after they were hidden using hideDataColumns method. Accepts one parameter which can be a number or an array of numbers, in which 0 refers to the first data series, and so on.

Events

Name Description Properties
rangechange Zoom range changed. Fired after the user modified the visible time range but not after a call to setVisibleChartRange method.
Note: It is advised not to use the event properties, but rather get them by calling getVisibleChartRange method.
  • start: Date. The start time of the zoom range.
  • end: Date. The end time of the zoom range.
ready The chart is ready for external method calls. If you want to interact with the chart, and call methods after you draw it, you should set up a listener for this event before you call the draw method, and call them only after the event was fired None
select When the user clicks on an annotation flag (marker), the corresponding cell in the data table is selected. The visualization then fires this event. None

Note: Because of certain limitations, events might not be thrown if you are accessing the page in your browser as a file (e.g., "file://") rather than from a server (e.g., "http://www").

Data Policy

All code and data are processed and rendered in the browser. No data is sent to any server.

Notes

Because of Flash security settings, this (and all Flash-based visualizations) might not work correctly when accessed from a file location in the browser (e.g., file:///c:/webhost/myhost/myviz.html) rather than from a web server URL (e.g., http://www.myhost.com/myviz.html). This is typically a testing issue only. You can overcome this issue as described on the Macromedia web site.