©2009 Google -
Code Home -
Terms of Service -
Privacy Policy -
Site Directory
Google Code offered in:
English -
Español -
日本語 -
한국어 -
Português -
Pусский -
中文(简体) -
中文(繁體)
An area chart that is rendered within the browser using SVG or VML. Displays tips when clicking on points. Animates lines when clicking on legend entries.
By: Google
Code it yourself on the Visualization Playground
<html>
<head>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["areachart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Year');
data.addColumn('number', 'Sales');
data.addColumn('number', 'Expenses');
data.addRows(4);
data.setValue(0, 0, '2004');
data.setValue(0, 1, 1000);
data.setValue(0, 2, 400);
data.setValue(1, 0, '2005');
data.setValue(1, 1, 1170);
data.setValue(1, 2, 460);
data.setValue(2, 0, '2006');
data.setValue(2, 1, 660);
data.setValue(2, 2, 1120);
data.setValue(3, 0, '2007');
data.setValue(3, 1, 1030);
data.setValue(3, 2, 540);
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(data, {width: 400, height: 240, legend: 'bottom', title: 'Company Performance'});
}
</script>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>
The google.load package name is "areachart".
google.load("visualization", "1", {packages: ["areachart"]});
The visualization's class name is google.visualization.AreaChart
var visualization = new google.visualization.AreaChart(container);
The first column should be a string, and contain the category label. Any number of columns can follow, all must be numeric. Each column is displayed as a separate line.
| Name | Type | Default | Description |
|---|---|---|---|
| axisColor | string or Object | default color | The color of the axis. Possible values are as those of the backgroundColor configuration option. |
| axisBackgroundColor | string or Object | default color | The border around axis background. Possible values are as those of the backgroundColor configuration option. |
| axisFontSize | number | automatic | Font size of the chart axis text, in pixels. |
| backgroundColor | string or Object | default color | The background color for the main area of the chart.
May be one of the following options:
|
| borderColor | string or Object | default color | The border around chart elements. Possible values are as those of the backgroundColor configuration option. |
| colors | Array of strings | Default colors | The colors to use for the chart elements. An array of strings. Each element is a string that is a color supported by HTML, for example 'red' or '#00cc00'. |
| enableTooltip | boolean | true | If set to true, tooltips are shown when the user clicks on a data point. |
| focusBorderColor | string or Object | default color | The border around chart elements that are in focus (pointed by the mouse). Possible values are as those of the backgroundColor configuration option. |
| height | number | Container's height | Height of the chart in pixels. |
| isStacked | boolean | false | If set to true, line values are stacked (accumulated). |
| legend | string | 'right' | Position and type of legend. Can be one of the following:
|
| legendBackgroundColor | string or Object | default color | The background color for the legend area of the chart. Possible values are as those of the backgroundColor configuration option. |
| legendFontSize | number | automatic | The size of the legend font, in pixels. |
| legendTextColor | string or Object | default color | The color for the text entries of the legend. Possible values are as those of the backgroundColor configuration option. |
| lineSize | number | 2 | Line width in pixels. Use zero to hide all lines and show only the points. |
| logScale | boolean | false | If true, the main axis should be scaled logarithmically. |
| max | number | automatic | Specifies the highest Y axis grid line. The actual grid line will be the greater of two values: the max option value, or the highest data value, rounded up to the next higher grid mark. |
| min | number | automatic | Specifies the lowest Y axis grid line. The actual grid line will be the lower of two values: the min option value, or the lowest data value, rounded down to the next lower grid mark. |
| pointSize | number | 3 | Size of displayed points in pixels. Use zero to hide all points. |
| reverseAxis | boolean | false | If set to true, will draw categories from right to left. The default is to draw left-to-right. |
| showCategories | boolean | true | If true, will show category labels. If false, will not. |
| title | string | no title | Text to display above the chart. |
| titleX | string | no title | Text to display below the horizontal axis. |
| titleY | string | no title | Text to display by the vertical axis. |
| titleColor | string or Object | default color | The color for the chart's title. Possible values are as those of the backgroundColor configuration option. |
| titleFontSize | number | automatic | The font size for the chart title, in pixels. |
tooltipFontSize |
number | 11 | The font size of the tooltip text. This might be reduced, if the tooltip is too small to hold the text in the specified font. |
| tooltipHeight |
number | 60 | The height of the tooltip, in pixels. The tooltip height is fixed; it will never grow or shrink to fit the length or font size of the text. But anything greater than 1/3 the chart height will be cropped. |
| tooltipWidth | number | 120 | The width of the tooltip, in pixels. The tooltip width is fixed; it will never grow or shrink to fit the length or font size of the text. But anything greater than the chart width will be cropped. |
| width | number | Container's width | Width of the chart in pixels. |
| Method | Return Type | Description |
|---|---|---|
draw(data, options) |
none | Draws the chart. |
getSelection() |
Array of selection elements | Standard getSelection() implementation. Selected elements are column and
cell elements. Only one column or cell can be selected at a time by the user. |
setSelection() |
none | Standard setSelection() implementation, but supports selection of only one
element. Treats every selection entry as a column or cell selection. Note that
the label column cannot be selected. |
| Name | Description | Properties |
|---|---|---|
onmouseover |
Fired when the user mouses over a point, and passes in the row and column indexes of the corresponding cell. | row, column |
onmouseout |
Fired when the user mouses away from a point, and passes in the row and column indexes of the corresponding cell. | row, column |
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 |
Fired when the user clicks a point or legend. When
a point is selected, the corresponding cell in the data table is
selected; when a legend
is selected, the corresponding column in the data table is selected.
To learn what has been selected, call getSelection(). |
None |
All code and data are processed and rendered in the browser. No data is sent to any server.