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
ordatetime
, and specifies the X value of the point on the chart. If this column is of typedate
(and notdatetime
) 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 setallowHtml
totrue
; 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
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()
.
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.
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.
scaleType
.scaleType
.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.
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'.
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.
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
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.
draw
method,
and call them only after the event was firedNote: 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 .