Saturday, March 23, 2013

Overview

An area chart that is rendered within the browser using SVG or VML. Displays tips when hovering over points.
By: Google
This is the new version of the area chart.
For tips on how to migrate to the new charts, please see the release notes.
If you need to access the older version, you can find the documentation here.

Example

Code it yourself on the Visualization Playground
<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Year', 'Sales', 'Expenses'],
          ['2004',  1000,      400],
          ['2005',  1170,      460],
          ['2006',  660,       1120],
          ['2007',  1030,      540]
        ]);

        var options = {
          title: 'Company Performance',
          hAxis: {title: 'Year',  titleTextStyle: {color: 'red'}}
        };

        var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
        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 "corechart".
  google.load("visualization", "1", {packages: ["corechart"]});
The visualization's class name is google.visualization.AreaChart
  var visualization = new google.visualization.AreaChart(container);
Warning: You cannot load both areachart and corechart packages at the same time on the same page.

Data Format

Rows: Each row in the table represents a set of data points with the same x-axis location.
Columns:
 Column 0Column 1...Column N
Purpose: Line 1 values...Line N values
Data Type: number...number
Role:domaindata...data
Optional column roles: ...

Configuration Options

NameTypeDefaultDescription
animation.durationnumber0The duration of the animation, in milliseconds. For details, see the animation documentation.
animation.easingstring'linear'The easing function applied to the animation. The following options are available:
  • 'linear' - Constant speed.
  • 'in' - Ease in - Start slow and speed up.
  • 'out' - Ease out - Start fast and slow down.
  • 'inAndOut' - Ease in and out - Start slow, speed up, then slow down.
areaOpacitynumber, 0.0–1.00.3The default opacity of the colored area under an area chart series, where 0.0 is fully transparent and 1.0 is fully opaque. To specify opacity for an individual series, set the areaOpacity value in the series property.
axisTitlesPositionstring'out'
Where to place the axis titles, compared to the chart area. Supported values:
  • in - Draw the axis titles inside the the chart area.
  • out - Draw the axis titles outside the chart area.
  • none - Omit the axis titles.
backgroundColorstring or object'white'The background color for the main area of the chart. Can be either a simple HTML color string, for example: 'red' or '#00cc00', or an object with the following properties.
backgroundColor.strokestring'#666'The color of the chart border, as an HTML color string.
backgroundColor.strokeWidthnumber0The border width, in pixels.
backgroundColor.fillstring'white'The chart fill color, as an HTML color string.
chartAreaObjectnullAn object with members to configure the placement and size of the chart area (where the chart itself is drawn, excluding axis and legends). Two formats are supported: a number, or a number followed by %. A simple number is a value in pixels; a number followed by % is a percentage. Example: chartArea:{left:20,top:0,width:"50%",height:"75%"}
chartArea.leftnumber or stringautoHow far to draw the chart from the left border.
chartArea.topnumber or stringautoHow far to draw the chart from the top border.
chartArea.widthnumber or stringautoChart area width.
chartArea.heightnumber or stringautoChart area height.
colorsArray of stringsdefault colorsThe colors to use for the chart elements. An array of strings, where each element is an HTML color string, for example: colors:['red','#004411'].
enableInteractivitybooleantrueWhether the chart throws user-based events or reacts to user interaction. If false, the chart will not throw 'select' or other interaction-based events (but will throw ready or error events), and will not display hovertext or otherwise change depending on user input.
focusTargetstring'datum'
The type of the entity that receives focus on mouse hover. Also affects which entity is selected by mouse click, and which data table element is associated with events. Can be one of the following:
  • 'datum' - Focus on a single data point. Correlates to a cell in the data table.
  • 'category' - Focus on a grouping of all data points along the major axis. Correlates to a row in the data table.
In focusTarget 'category' the tooltip displays all the category values. This may be useful for comparing values of different series.
fontSizenumberautomaticThe default font size, in pixels, of all text in the chart. You can override this using properties for specific chart elements.
fontNamestring'Arial'The default font face for all text in the chart. You can override this using properties for specific chart elements.
hAxisObjectnull
An object with members to configure various horizontal axis elements. To specify properties of this object, you can use object literal notation, as shown here:
 {title: 'Hello',  titleTextStyle: {color: '#FF0000'}}
hAxis.baselinenumberautomaticThe baseline for the horizontal axis.
This option is only supported for a continuous axis.
hAxis.baselineColornumber'black'The color of the baseline for the horizontal axis. Can be any HTML color string, for example: 'red' or '#00cc00'.
This option is only supported for a continuous axis.
hAxis.direction1 or -11The direction in which the values along the horizontal axis grow. Specify -1 to reverse the order of the values.
hAxis.formatstringauto
A format string for numeric or date axis labels.
For number axis labels, this is a subset of the decimal formatting ICU pattern set. For instance, {format:'#,###%'} will display values "1,000%", "750%", and "50%" for values 10, 7.5, and 0.5.
For date axis labels, this is a subset of the date formatting ICU pattern set. For instance, {format:'MMM d, y'} will display the value "Jul 1, 2011" for the date of July first in 2011.
The actual formatting applied to the label is derived from the locale the API has been loaded with. For more details, see loading charts with a specific locale.
This option is only supported for a continuous axis.
hAxis.gridlinesObjectnull
An object with members to configure the gridlines on the horizontal axis. To specify properties of this object, you can use object literal notation, as shown here:
 {color: '#333', count: 4}
This option is only supported for a continuous axis.
hAxis.gridlines.colorstring'#CCC'The color of the horizontal gridlines inside the chart area. Specify a valid HTML color string.
hAxis.gridlines.countnumber5The number of horizontal gridlines inside the chart area. Minimum value is 2.
hAxis.minorGridlinesObjectnullAn object with members to configure the minor gridlines on the horizontal axis, similar to the hAxis.gridlines option.
This option is only supported for a continuous axis.
hAxis.minorGridlines.colorstringA blend of the gridline and background colorsThe color of the horizontal minor gridlines inside the chart area. Specify a valid HTML color string.
hAxis.minorGridlines.countnumber0The number of horizontal minor gridlines between two regular gridlines.
hAxis.logScalebooleanfalsehAxis property that makes the horizontal axis a logarithmic scale (requires all values to be positive). Set to true for yes.
This option is only supported for a continuous axis.
hAxis.textPositionstring'out'
Position of the horizontal axis text, relative to the chart area. Supported values: 'out', 'in', 'none'.
hAxis.textStyleObject{color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>}
An object that specifies the horizontal axis text style. The object has this format:
 {color: <string>, fontName: <string>, fontSize: <number>}
The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.
hAxis.titlestringnullhAxis property that specifies the title of the horizontal axis.
hAxis.titleTextStyleObject{color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>}
An object that specifies the horizontal axis title text style. The object has this format:
 {color: <string>, fontName: <string>, fontSize: <number>}
The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.
hAxis.allowContainerBoundaryTextCufoffbooleanfalseIf false, will hide outermost labels rather than allow them to be cropped by the chart container. If true, will allow label cropping.
This option is only supported for a discrete axis.
hAxis.slantedTextbooleanautomaticIf true, draw the horizontal axis text at an angle, to help fit more text along the axis; if false, draw horizontal axis text upright. Default behavior is to slant text if it cannot all fit when drawn upright. Notice that this option is available only when the hAxis.textPosition is set to 'out' (which is the default).
This option is only supported for a discrete axis.
hAxis.slantedTextAnglenumber, 1—9030The angle of the horizontal axis text, if it's drawn slanted. Ignored if hAxis.slantedText is false, or is in auto mode, and the chart decided to draw the text horizontally.
This option is only supported for a discrete axis.
hAxis.maxAlternationnumber2Maximum number of levels of horizontal axis text. If axis text labels become too crowded, the server might shift neighboring labels up or down in order to fit labels closer together. This value specifies the most number of levels to use; the server can use fewer levels, if labels can fit without overlapping.
This option is only supported for a discrete axis.
hAxis.maxTextLinesnumberautoMaximum number of lines allowed for the text labels. Labels can span multiple lines if they are too long, and the nuber of lines is, by default, limited by the height of the available space.
This option is only supported for a discrete axis.
hAxis.minTextSpacingnumberThe value ofhAxis.textStyle.fontSizeMinimum horizontal spacing, in pixels, allowed between two adjacent text labels. If the labels are spaced too densely, or they are too long, the spacing can drop below this threshold, and in this case one of the label-unclutter measures will be applied (e.g, truncating the lables or dropping some of them).
This option is only supported for a discrete axis.
hAxis.showTextEverynumberautomaticHow many horizontal axis labels to show, where 1 means show every label, 2 means show every other label, and so on. Default is to try to show as many labels as possible without overlapping.
This option is only supported for a discrete axis.
hAxis.maxValuenumberautomatichAxis property that specifies the highest horizontal axis grid line. The actual grid line will be the greater of two values: the maxValueoption value, or the highest data value, rounded up to the next higher grid mark.
This option is only supported for a continuous axis.
hAxis.minValuenumberautomatichAxis property that specifies the lowest horizontal axis grid line. The actual grid line will be the lower of two values: the minValue option value, or the lowest data value, rounded down to the next lower grid mark.
This option is only supported for a continuous axis.
hAxis.viewWindowModestring'pretty' if hAxis.viewWindowis null, 'explicit' otherwise
Specifies how to scale the horizontal axis to render the values within the chart area. The following string values are supported:
  • 'pretty' - Scale the horizontal values so that the maximum and minimum data values are rendered a bit inside the left and right of the chart area.
  • 'maximized' - Scale the horizontal values so that the maximum and minimum data values touch the left and right of the chart area.
  • 'explicit' - Specify the left and right scale values of the chart area. Data values outside these values will be cropped. You must specify an hAxis.viewWindow object describing the maximum and minimum values to show.
This option is only supported for a continuous axis.
hAxis.viewWindowObjectnullSpecifies the cropping range of the horizontal axis.
hAxis.viewWindow.maxnumberauto
  • For a continuous axis:
    The maximum horizontal data value to render. Has an effect only if hAxis.viewWindowMode='explicit'.
  • For a discrete axis:
    The zero-based row index where the cropping window ends. Data points at this index and higher will be cropped out. In conjunction with vAxis.viewWindowMode.min, it defines a half-opened range [min, max) that denotes the element indices to display. In other words, every index such that min <= index < max will be displayed.
hAxis.viewWindow.minnumberauto
  • For a continuous axis:
    The minimum horizontal data value to render. Has an effect only if hAxis.viewWindowMode='explicit'.
  • For a discrete axis:
    The zero-based row index where the cropping window begins. Data points at indices lower than this will be cropped out. In conjunction with vAxis.viewWindowMode.max, it defines a half-opened range [min, max) that denotes the element indices to display. In other words, every index such that min <= index < max will be displayed.
heightnumberheight of the containing elementHeight of the chart, in pixels.
isHtmlbooleanfalseIf set to true, use HTML-rendered (rather than SVG-rendered) tooltips. See Customizing Tooltip Content for more details.
isStackedbooleanfalseIf set to true, series elements are stacked.
legendObjectnull
An object with members to configure various aspects of the legend. To specify properties of this object, you can use object literal notation, as shown here:
{position: 'top', textStyle: {color: 'blue', fontSize: 16}}
legend.positionstring'right'Position of the legend. Can be one of the following:
  • 'right' - To the right of the chart. Incompatible with the vAxes option.
  • 'top' - Above the chart.
  • 'bottom' - Below the chart.
  • 'in' - Inside the chart, by the top left corner.
  • 'none' - No legend is displayed.
legend.alignmentstringautomaticAlignment of the legend. Can be one of the following:
  • 'start' - Aligned to the start of the area allocated for the legend.
  • 'center' - Centered in the area allocated for the legend.
  • 'end' - Aligned to the end of the area allocated for the legend.
Start, center, and end are relative to the style -- vertical or horizontal -- of the legend. For example, in a 'right' legend, 'start' and 'end' are at the top and bottom, respectively; for a 'top' legend, 'start' and 'end' would be at the left and right of the area, respectively.
The default value depends on the legend's position. For 'bottom' legends, the default is 'center'; other legends default to 'start'.
legend.textStyleObject{color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>}
An object that specifies the legend text style. The object has this format:
 {color: <string>, fontName: <string>, fontSize: <number>}
The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.
lineWidthnumber2Data line width in pixels. Use zero to hide all lines and show only the points. You can override values for individual series using theseries property.
pointSizenumber0Diameter of displayed points in pixels. Use zero to hide all points. You can override values for individual series using the series property.
reverseCategoriesbooleanfalseIf set to true, will draw series from right to left. The default is to draw left-to-right.
This option is only supported for a discrete major axis.
seriesArray of objects, or object with nested objects{}
An array of objects, each describing the format of the corresponding series in the chart. To use default values for a series, specify an empty object {}. If a series or a value is not specified, the global value will be used. Each object supports the following properties:
  • color - The color to use for this series. Specify a valid HTML color string.
  • targetAxisIndex - Which axis to assign this series to, where 0 is the default axis, and 1 is the opposite axis. Default value is 0; set to 1 to define a chart where different series are rendered against different axes. At least one series much be allocated to the default axis. You can define a different scale for different axes.
  • pointSize - Overrides the global pointSize value for this series.
  • lineWidth - Overrides the global lineWidth value for this series.
  • areaOpacity - Overrides the global areaOpacity for this series.
  • visibleInLegend - A boolean value, where true means that the series should have a legend entry, and false means that it should not. Default is true.
You can specify either an array of objects, each of which applies to the series in the order given, or you can specify an object where each child has a numeric key indicating which series it applies to. For example, the following two declarations are identical, and declare the first series as black and absent from the legend, and the fourth as red and absent from the legend:
series: [{color: 'black', visibleInLegend: false},{}, {}, {color: 'red', visibleInLegend: false}]
series: {0:{color: 'black', visibleInLegend: false}, 3:{color: 'red', visibleInLegend: false}}
themestringnullA theme is a set of predefined option values that work together to achieve a specific chart behavior or visual effect. Currently only one theme is available:
  • 'maximized' - Maximizes the area of the chart, and draws the legend and all of the labels inside the chart area. Sets the following options:
    chartArea: {width: '100%', height: '100%'},
    legend: {position: 'in'},
    titlePosition: 'in', axisTitlesPosition: 'in',
    hAxis: {textPosition: 'in'}, vAxis: {textPosition: 'in'}
titlestringno titleText to display above the chart.
titlePositionstring'out'
Where to place the chart title, compared to the chart area. Supported values:
  • in - Draw the title inside the chart area.
  • out - Draw the title outside the chart area.
  • none - Omit the title.
titleTextStyleObject{color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>}
An object that specifies the title text style. The object has this format:
 {color: <string>, fontName: <string>, fontSize: <number>}
The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.
tooltipObjectnull
An object with members to configure various tooltip elements. To specify properties of this object, you can use object literal notation, as shown here:
 {textStyle: {color: '#FF0000'}, showColorCode: true}
tooltip.showColorCodebooleanautomaticIf true, show colored squares next to the series information in the tooltip. The default is true when focusTarget is set to 'category', otherwise the default is false.
tooltip.textStyleObject{color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>}
An object that specifies the tooltip text style. The object has this format:
 {color: <string>, fontName: <string>, fontSize: <number>}
The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.
tooltip.triggerstring'focus'
The user interaction that causes the tooltip to be displayed:
  • 'focus' - The tooltip will be displayed when the user hovers over an element.
  • 'none' - The tooltip will not be displayed.
vAxesArray of object, or object with child objectsnull
Specifies properties for individual vertical axes, if the chart has multiple vertical axes. Each child object is a vAxis object, and can contain all the properties supported by vAxis. These property values override any global settings for the same property.
To specify a chart with multiple vertical axes, first define a new axis using series.targetAxisIndex, then configure the axis usingvAxes. The following example assigns series 2 to the right axis and specifies a custom title and text style for it:
series:{2:{targetAxisIndex:1}}, vAxes:{1:{title:'Losses',textStyle:{color: 'red'}}}
This property can be either an object or an array: the object is a collection of objects, each with a numeric label that specifies the axis that it defines--this is the format shown above; the array is an array of objects, one per axis. For example, the following array-style notation is identical to the vAxis object shown above:
vAxes:[
{}, // Nothing specified for axis 0
{title:'Losses',textStyle:{color: 'red'}} // Axis 1
]
vAxisObjectnull
An object with members to configure various vertical axis elements. To specify properties of this object, you can use object literal notation, as shown here:
 {title: 'Hello', titleTextStyle: {color: '#FF0000'}}
vAxis.baselinenumberautomaticvAxis property that specifies the baseline for the vertical axis. If the baseline is larger than the highest grid line or smaller than the lowest grid line, it will be rounded to the closest gridline.
vAxis.baselineColornumber'black'Specifies the color of the baseline for the vertical axis. Can be any HTML color string, for example: 'red' or '#00cc00'.
vAxis.direction1 or -11The direction in which the values along the vertical axis grow. Specify -1 to reverse the order of the values.
vAxis.formatstringautoA format string for numeric axis labels. This is a subset of the ICU pattern set. For instance, {format:'#,###%'} will display values "1,000%", "750%", and "50%" for values 10, 7.5, and 0.5.
The actual formatting applied to the label is derived from the locale the API has been loaded with. For more details, see loading charts with a specific locale.
vAxis.gridlinesObjectnull
An object with members to configure the gridlines on the vertical axis. To specify properties of this object, you can use object literal notation, as shown here:
 {color: '#333', count: 4}
vAxis.gridlines.colorstring'#CCC'The color of the vertical gridlines inside the chart area. Specify a valid HTML color string.
vAxis.gridlines.countnumber5The number of vertical gridlines inside the chart area. Minimum value is 2.
vAxis.minorGridlinesObjectnullAn object with members to configure the minor gridlines on the vertical axis, similar to the vAxis.gridlines option.
vAxis.minorGridlines.colorstringA blend of the gridline and background colorsThe color of the vertical minor gridlines inside the chart area. Specify a valid HTML color string.
vAxis.minorGridlines.countnumber0The number of vertical minor gridlines between two regular gridlines.
vAxis.logScalebooleanfalseIf true, makes the vertical axis a logarithmic scale Note: All values must be positive.
vAxis.textPositionstring'out'
Position of the vertical axis text, relative to the chart area. Supported values: 'out', 'in', 'none'.
vAxis.textStyleObject{color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>}
An object that specifies the vertical axis text style. The object has this format:
 {color: <string>, fontName: <string>, fontSize: <number>}
The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.
vAxis.titlestringno titlevAxis property that specifies a title for the vertical axis.
vAxis.titleTextStyleObject{color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>}
An object that specifies the vertical axis title text style. The object has this format:
 {color: <string>, fontName: <string>, fontSize: <number>}
The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.
vAxis.maxValuenumberautomaticvAxis property that specifies the highest vertical axis grid line. The actual grid line will be the greater of two values: the maxValue option value, or the highest data value, rounded up to the next higher grid mark.
vAxis.minValuenumberautomaticvAxis property that specifies the lowest vertical axis grid line. The actual grid line will be the lower of two values: the minValue option value, or the lowest data value, rounded down to the next lower grid mark.
vAxis.viewWindowModestring'pretty' if vAxis.viewWindowis null, 'explicit' otherwise
Specifies how to scale the vertical axis to render the values within the chart area. The following string values are supported:
  • 'pretty' - Scale the vertical values so that the maximum and minimum data values are rendered a bit inside the top and bottom of the chart area.
  • 'maximized' - Scale the vertical values so that the maximum and minimum data values touch the top and bottom of the chart area.
  • 'explicit' - Specify the top and bottom scale values of the chart area. Data values outside these values will be cropped. You must specify a vAxis.viewWindow object describing the maximum and minimum values to show.
vAxis.viewWindowObjectnullSpecifies the cropping range of the vertical axis.
vAxis.viewWindow.maxnumberautoThe maximum vertical data value to render. Has an effect only if vAxis.viewWindowMode='explicit'.
vAxis.viewWindow.minnumberautoThe minimum horizontal data value to render. Has an effect only if vAxis.viewWindowMode='explicit'.
widthnumberwidth of the containing elementWidth of the chart, in pixels.

Methods

MethodReturn TypeDescription
draw(data, options)noneDraws the chart. The chart accepts further method calls only after the ready event is fired. Extended description.
getSelection()Array of selection elementsReturns an array of the selected chart entities. Selectable entities are points, annotations, legend entries and categories. A point or annotation correlates to a cell in the data table, a legend entry to a column (row index is null), and a category to a row (column index is null). For this chart, only one entity can be selected at any given moment. Extended description.
setSelection()noneSelects the specified chart entities. Cancels any previous selection. Selectable entities are points, annotations, legend entries and categories. A point or annotation correlates to a cell in the data table, a legend entry to a column (row index is null), and a category to a row (column index is null). For this chart, only one entity can be selected at a time. Extended description.
clearChart()noneClears the chart, and releases all of its allocated resources.

Events

NameDescriptionProperties
animationfinishFired when transition animation is complete.None
errorFired when an error occurs when attempting to render the chart.id, message
onmouseoverFired when the user mouses over a visual entity. Passes back the row and column indices of the corresponding data table element. A point or annotation correlates to a cell in the data table, a legend entry to a column (row index is null), and a category to a row (column index is null).row, column
onmouseoutFired when the user mouses away from a visual entity. Passes back the row and column indices of the corresponding data table element. A point or annotation correlates to a cell in the data table, a legend entry to a column (row index is null), and a category to a row (column index is null).row, column
readyThe 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
selectFired when the user clicks a visual entity. To learn what has been selected, call getSelection().None

0 comments:

Post a Comment