Google Charts

Annotation Chart

Overview

Annotation charts are interactive time series line charts that support annotations. Unlike the annotated timeline, which uses Flash, annotation charts are SVG/VML and should be preferred whenever possible.

Confusion alert: Currently, the Google Annotation Chart is distinct from the annotations that other Google charts (currently area, bar, column, combo, line, and scatter) support. In those charts, the annotations are specified in a separate datatable column, and displayed as short bits of text that users can hover over to see the full annotation text. In contrast, the Annotation Chart displays the full annotations on the right-hand side, as shown below.

Example

<html>
  <head>
    <script type='text/javascript' src='http://www.google.com/jsapi'></script>
    <script type='text/javascript'>
      google.load('visualization', '1.1', {'packages':['annotationchart']});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('date', 'Date');
        data.addColumn('number', 'Kepler-22b mission');
        data.addColumn('string', 'Kepler title');
        data.addColumn('string', 'Kepler text');
        data.addColumn('number', 'Gliese 163 mission');
        data.addColumn('string', 'Gliese title');
        data.addColumn('string', 'Gliese text');
        data.addRows([
          [new Date(2314, 2, 15), 12400, undefined, undefined,
                                  10645, undefined, undefined],
          [new Date(2314, 2, 16), 24045, 'Lalibertines', 'First encounter',
                                  12374, undefined, undefined],
          [new Date(2314, 2, 17), 35022, 'Lalibertines', 'They are very tall',
                                  15766, 'Gallantors', 'First Encounter'],
          [new Date(2314, 2, 18), 12284, 'Lalibertines', 'Attack on our crew!',
                                  34334, 'Gallantors', 'Statement of shared principles'],
          [new Date(2314, 2, 19), 8476, 'Lalibertines', 'Heavy casualties',
                                  66467, 'Gallantors', 'Mysteries revealed'],
          [new Date(2314, 2, 20), 0, 'Lalibertines', 'All crew lost',
                                  79463, 'Gallantors', 'Omniscience achieved']
        ]);

        var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div'));

        var options = {
          displayAnnotations: true,
        };

        chart.draw(data, options);
      }
    </script>
  </head>

  <body>
    <div id='chart_div' style='width: 900px; height: 500px;'></div>
  </body>
</html>

Loading

The google.load package name is "annotationchart"

  google.load("visualization", "1.1", {packages: ['annotationchart']});

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

  var visualization = new google.visualization.AnnotationChart(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.
allValuesSuffix string none A suffix to be added to all values in the legend and tick labels in the vertical axes.
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 first series in the chart, scaled to fit the height of the zoom selector.

displayZoomButtons boolean true Whether to show the zoom buttons ("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, and 0 means no fill at all. The fill color is the same color as the line above it.
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.

This is similar to maxValue in core charts.

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.

This is similar to minValue in core charts.

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 the 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'.

scaleFormat string '#' Number format to be used for the axis tick labels. The default of '#' displays as an integer.
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 its 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.
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
clearChart() none Clears the chart, and releases all its allocated resources.
draw(data, options, state) none Draws the chart.
getContainer() Handle to a DOM element Retrieves a handle to the container element containing the annotation chart.
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

Annotation charts don't support any events yet.

Data Policy

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

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.