Bar Charts Stay organized with collections Save and categorize content based on your preferences.
Page Summary
Google Bar Charts are horizontal column charts that display tooltips on hover and can be rendered using SVG or VML.
Bar appearance can be customized using the
stylerole with various color and CSS-like properties, although mixing styles is not recommended.Bar labels and data values can be added using the
annotationrole and customized with formatters.Stacked bar charts group values on top of each other and can display them as absolute, percentage, or relative values.
Material bar charts offer a newer design style, while Dual-X and Top-X charts provide advanced axis configurations, both available only in Material charts.
Overview
Google bar charts are rendered in the browser usingSVG orVML,whichever is appropriate for the user's browser. Like all Googlecharts, bar charts display tooltips when the user hovers over thedata. For a vertical version of this chart, seethecolumnchart.
Examples
Coloring bars
Let's chart the densities of four precious metals:
Above, all colors are the default blue. That's because they're all part of the same series; if there were a second series, that would have been colored red. We can customize these colors with thestyle role:
There are three different ways to choose the colors, and our datatable showcases them all: RGB values, English color names, and aCSS-like declaration:
var data = google.visualization.arrayToDataTable([ ['Element', 'Density',{ role: 'style' }], ['Copper', 8.94,'#b87333'], // RGB value ['Silver', 10.49,'silver'], // English color name ['Gold', 19.30,'gold'], ['Platinum', 21.45,'color: #e5e4e2' ], // CSS-style declaration ]);Bar styles
Thestyle role lets you control several aspects of bar appearance with CSS-like declarations:
coloropacityfill-colorfill-opacitystroke-colorstroke-opacitystroke-width
We don't recommend that you mix styles too freely inside achart—pick a style and stick with it—but to demonstrateall the style attributes, here's a sampler:
The first two bars each use a specificcolor (thefirst with an English name, the second with an RGBvalue). Noopacity was chosen, so the default of 1.0(fully opaque) is used; that's why the second bar obscures thegridline behind it. In the third bar, anopacity of 0.2is used, revealing the gridline. In the fourth bar, three styleattributes are used:stroke-colorandstroke-width to draw the border,andfill-color to specify the color of the rectangleinside. The rightmost bar additionallyusesstroke-opacity andfill-opacity tochoose opacities for the border and fill:
function drawChart() { var data = google.visualization.arrayToDataTable([ ['Year', 'Visitations',{ role: 'style' } ], ['2010', 10,'color: gray'], ['2020', 14,'color: #76A7FA'], ['2030', 16,'opacity: 0.2'], ['2040', 22,'stroke-color: #703593; stroke-width: 4; fill-color: #C5A5CF'], ['2050', 28,'stroke-color: #871B47; stroke-opacity: 0.6; stroke-width: 8; fill-color: #BC5679; fill-opacity: 0.2'] ]);Labeling bars
Charts have several kinds of labels, such as tick labels, legendlabels, and labels in the tooltips. In this section, we'll see how toput labels inside (or near) the bars in a bar chart.
Let's say we wanted to annotate each bar with the appropriatechemical symbol. We can do that with theannotation role:
In our data table, we define a new column with{ role:'annotation' } to hold our bar labels:
var data = google.visualization.arrayToDataTable([ ['Element', 'Density', { role: 'style' },{ role: 'annotation' } ], ['Copper', 8.94, '#b87333','Cu' ], ['Silver', 10.49, 'silver','Ag' ], ['Gold', 19.30, 'gold','Au' ], ['Platinum', 21.45, 'color: #e5e4e2','Pt' ] ]);While users can hover over the bars to see the data values, youmight want to include them on the bars themselves:
This is a little more complicated than it should be, because wecreate aDataView to specify the annotation for eachbar.
<script type="text/javascript"> google.charts.load("current", {packages:["corechart"]}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ["Element", "Density", { role: "style" } ], ["Copper", 8.94, "#b87333"], ["Silver", 10.49, "silver"], ["Gold", 19.30, "gold"], ["Platinum", 21.45, "color: #e5e4e2"] ]);var view = new google.visualization.DataView(data); view.setColumns([0, 1, { calc: "stringify", sourceColumn: 1, type: "string", role: "annotation" }, 2]); var options = { title: "Density of Precious Metals, in g/cm^3", width: 600, height: 400, bar: {groupWidth: "95%"}, legend: { position: "none" }, }; var chart = new google.visualization.BarChart(document.getElementById("barchart_values")); chart.draw(view, options); } </script><div id="barchart_values" style="width: 900px; height: 300px;"></div>If we wanted to format the value differently, we could define aformatter and wrap it in a function like this:
function getValueAt(column, dataTable, row) { return dataTable.getFormattedValue(row, column); }Then we could call it withcalc: getValueAt.bind(undefined, 1).
If the label is too big to fit entirely inside the bar, it's displayed outside:
Stacked bar charts
Astacked bar chart is a bar chart that places related values atop one another. If there are any negative values, they are stacked in reverse order below the chart's axis baseline. Stacked bar charts are typically used when a category naturally divides into components. For instance, consider some hypothetical book sales, divided by genre and compared across time:
You create a stacked bar chart by settingtheisStacked option totrue:
var data = google.visualization.arrayToDataTable([ ['Genre', 'Fantasy & Sci Fi', 'Romance', 'Mystery/Crime', 'General', 'Western', 'Literature', { role: 'annotation' } ], ['2010', 10, 24, 20, 32, 18, 5, ''], ['2020', 16, 22, 23, 30, 16, 9, ''], ['2030', 28, 19, 29, 30, 12, 13, ''] ]); var options = { width: 600, height: 400, legend: { position: 'top', maxLines: 3 }, bar: { groupWidth: '75%' },isStacked: true }; Stacked bar charts also support 100% stacking, where the stacks of elements at each domain-value are rescaled such that they add up to 100%. The options for this areisStacked: 'percent', which formats each value as a percentage of 100%, andisStacked: 'relative', which formats each value as a fraction of 1. There is also anisStacked: 'absolute' option, which is functionally equivalent toisStacked: true.
Note in the 100% stacked chart on the right, the tick values are based on the relative 0-1 scale as fractions of 1, but the axis values are displayed as percentages. This is because the percentage axis ticks are the result of applying a format of "#.##%" to the relative 0-1 scale values. When usingisStacked: 'percent', be sure to specify any ticks using the relative 0-1 scale.
varoptions_stacked={isStacked:true,height:300,legend:{position:'top',maxLines:3},hAxis:{minValue:0}};
varoptions_fullStacked={isStacked:'percent',height:300,legend:{position:'top',maxLines:3},hAxis:{minValue:0,ticks:[0,.3,.6,.9,1]}};
Creating Material bar charts
In 2014, Google announced guidelines intended to support a commonlook and feel across its properties and apps (such as Android apps)that run on Google platforms. We call this effortMaterialDesign. We'll be providing "Material" versions of all our corecharts; you're welcome to use them if you like how they look.
Creating a Material Bar Chart is similar to creating what we'll nowcall a "Classic" Bar Chart. You load the Google Visualization API(although with the'bar' package instead ofthe'corechart' package), define your datatable, and thencreate an object (but of classgoogle.charts.Bar insteadofgoogle.visualization.BarChart).
Note: Material Charts will not work in oldversions of Internet Explorer. (IE8 and earlier versions don't supportSVG, which Material Charts require.)
Material Bar Charts have many small improvements over Classic BarCharts, including an improved color palette, rounded corners, clearerlabel formatting, tighter default spacing between series, softergridlines and titles (and the addition of subtitles).
<html> <head> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript"> google.charts.load('current', {'packages':['bar']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Year', 'Sales', 'Expenses', 'Profit'], ['2014', 1000, 400, 200], ['2015', 1170, 460, 250], ['2016', 660, 1120, 300], ['2017', 1030, 540, 350] ]); var options = { chart: { title: 'Company Performance', subtitle: 'Sales, Expenses, and Profit: 2014-2017', }, bars: 'horizontal' // Required for Material Bar Charts. }; var chart = new google.charts.Bar(document.getElementById('barchart_material')); chart.draw(data, google.charts.Bar.convertOptions(options)); } </script> </head> <body> <div></div> </body></html> The Material Charts are inbeta. The appearance and interactivity are largely final, but many of the options available in Classic Charts are not yet available in them. You can find a list of options that are not yet supported inthis issue.
Also, the way options are declared is not finalized, so if you are using any of the classic options, you must convert them to material options by replacing this line:chart.draw(data, options);
...with this:chart.draw(data,google.charts.Bar.convertOptions(options));
Usinggoogle.charts.Bar.convertOptions() allows you to take advantage of certain features, such as thehAxis/vAxis.format preset options.
Dual-X charts
Note: Dual-X axes are available only forMaterial charts (i.e., those with packagebar).
Sometimes you'll want to display two series in a bar chart, withtwo independent x-axes: a top axis for one series, and a bottom axisfor another:
Note that not only are our two x-axes labeled differently("parsecs" versus "apparent magnitude") but they each have their ownindependent scales and gridlines. If you want to customize thisbehavior, use thehAxis.gridlines options.
In the code below, theaxes andseriesoptions together specify the dual-X appearance of thechart. Theseries option specifies which axis to use foreach ('distance' and'brightness'; theyneedn't have any relation to the column names in thedatatable). Theaxes option then makes this chart adual-X chart, placing the'apparent magnitude' axis onthe top and the'parsecs' axis on the bottom.
<html> <head> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript"> google.charts.load('current', {'packages':['bar']}); google.charts.setOnLoadCallback(drawStuff); function drawStuff() { var data = new google.visualization.arrayToDataTable([ ['Galaxy', 'Distance', 'Brightness'], ['Canis Major Dwarf', 8000, 23.3], ['Sagittarius Dwarf', 24000, 4.5], ['Ursa Major II Dwarf', 30000, 14.3], ['Lg. Magellanic Cloud', 50000, 0.9], ['Bootes I', 60000, 13.1] ]); var options = { width: 800, chart: { title: 'Nearby galaxies', subtitle: 'distance on the left, brightness on the right' }, bars: 'horizontal', // Required for Material Bar Charts. series: { 0: { axis: 'distance' }, // Bind series 0 to an axis named 'distance'. 1: { axis: 'brightness' } // Bind series 1 to an axis named 'brightness'. }, axes: { x: { distance: {label: 'parsecs'}, // Bottom x-axis. brightness: {side: 'top', label: 'apparent magnitude'} // Top x-axis. } } }; var chart = new google.charts.Bar(document.getElementById('dual_x_div')); chart.draw(data, options); }; </script> </head> <body> <div></div> </body></html>Top-X charts
Note: Top-X axes are available only forMaterial charts (i.e., those with packagebar).
If you want to put the X-axis labels and title on the top of yourchart rather than the bottom, you can do that in Material charts withtheaxes.x option:
<html> <head> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript"> google.charts.load('current', {'packages':['bar']}); google.charts.setOnLoadCallback(drawStuff); function drawStuff() { var data = new google.visualization.arrayToDataTable([ ['Opening Move', 'Percentage'], ["King's pawn (e4)", 44], ["Queen's pawn (d4)", 31], ["Knight to King 3 (Nf3)", 12], ["Queen's bishop pawn (c4)", 10], ['Other', 3] ]); var options = { title: 'Chess opening moves', width: 900, legend: { position: 'none' }, chart: { title: 'Chess opening moves', subtitle: 'popularity by percentage' }, bars: 'horizontal', // Required for Material Bar Charts. axes: { x: { 0: { side: 'top', label: 'Percentage'} // Top x-axis. } }, bar: { groupWidth: "90%" } }; var chart = new google.charts.Bar(document.getElementById('top_x_div')); chart.draw(data, options); }; </script> </head> <body> <div></div> </body></html>Loading
Thegoogle.charts.load package name is"corechart". The visualization's class name isgoogle.visualization.BarChart.
google.charts.load("current",{packages:["corechart"]});
varvisualization=newgoogle.visualization.BarChart(container);
For Material Bar Charts, thegoogle.charts.load packagename is"bar".The visualization's class nameisgoogle.charts.Bar.
google.charts.load("current",{packages:["bar"]});
varchart=newgoogle.charts.Bar(container);
Data format
Rows: Each row in the table represents a group of bars.
Columns:
| Column 0 | Column 1 | ... | ColumnN | |
|---|---|---|---|---|
| Purpose: |
| Bar 1 values in this group | ... | BarN values in this group |
| Data Type: |
| number | ... | number |
| Role: | domain | data | ... | data |
| Optionalcolumn roles: | ... |
Configuration options
| Name | |
|---|---|
| animation.duration | The duration of the animation, in milliseconds. For details, see theanimation documentation. Type: number Default: 0 |
| animation.easing | The easing function applied to the animation. The following options are available:
Type: string Default: 'linear' |
| animation.startup | Determines if the chart will animate on the initial draw. If Type: boolean Default false |
| annotations.alwaysOutside | InBar and Column charts, if set to Type: boolean Default: false |
| annotations.datum | For charts that supportannotations, the annotations.datum object lets you override Google Charts' choice for annotations provided for individual data elements (such as values displayed with each bar on a bar chart). You can control the color withannotations.datum.stem.color, the stem length withannotations.datum.stem.length, and the style withannotations.datum.style.Type: object Default: color is "black"; length is 12; style is "point". |
| annotations.domain | For charts that supportannotations, the annotations.domain object lets you override Google Charts' choice for annotations provided for a domain (the major axis of the chart, such as the X axis on a typical line chart). You can control the color withannotations.domain.stem.color, the stem length withannotations.domain.stem.length, and the style withannotations.domain.style.Type: object Default: color is "black"; length is 5; style is "point". |
| annotations.boxStyle | For charts that supportannotations, the varoptions={annotations:{boxStyle:{//Coloroftheboxoutline.stroke:'#888',//Thicknessoftheboxoutline.strokeWidth:1,//x-radiusofthecornercurvature.rx:10,//y-radiusofthecornercurvature.ry:10,//Attributesforlineargradientfill.gradient:{//Startcolorforgradient.color1:'#fbf6a7',//Finishcolorforgradient.color2:'#33b679',//Whereontheboundarytostartand//endthecolor1/color2gradient,//relativetotheupperleftcorner//oftheboundary.x1:'0%',y1:'0%',x2:'100%',y2:'100%',//Iftrue,theboundaryforx1,//y1,x2,andy2isthebox.If//false,it's the entire chart.useObjectBoundingBoxUnits:true}}}}; This option is currently supported for area, bar, column, combo, line, and scatter charts. It is not supported by theAnnotation Chart. Type: object Default: null |
| annotations.highContrast | For charts that supportannotations, the annotations.highContrast boolean lets you override Google Charts' choice of the annotation color. By default,annotations.highContrast is true, which causes Charts to select an annotation color with good contrast: light colors on dark backgrounds, and dark on light. If you setannotations.highContrast to false and don't specify your own annotation color, Google Charts will use the default series color for the annotation:Type: boolean Default: true |
| annotations.stem | For charts that supportannotations, the annotations.stem object lets you override Google Charts' choice for the stem style. You can control color withannotations.stem.color and the stem length withannotations.stem.length. Note that the stem length option has no effect on annotations with style'line': for'line' datum annotations, the stem length is always the same as the text, and for'line' domain annotations, the stem extends across the entire chart.Type: object Default: color is "black"; length is 5 for domain annotations and 12 for datum annotations. |
| annotations.style | For charts that supportannotations, the annotations.style option lets you override Google Charts' choice of the annotation type. It can be either'line' or'point'.Type: string Default: 'point' |
| annotations.textStyle | For charts that supportannotations, the annotations.textStyle object controls the appearance of the text of the annotation:varoptions={annotations:{textStyle:{fontName:'Times-Roman',fontSize:18,bold:true,italic:true,//Thecolorofthetext.color:'#871b47',//Thecolorofthetextoutline.auraColor:'#d799ae',//Thetransparencyofthetext.opacity:0.8}}}; This option is currently supported for area, bar, column, combo, line, and scatter charts. It is not supported by the Annotation Chart. Type: object Default: null |
| axisTitlesPosition | Where to place the axis titles, compared to the chart area. Supported values:
Type: string Default: 'out' |
| backgroundColor | The background color for the main area of the chart. Can be either a simple HTML color string, for example: Type: string or object Default: 'white' |
| backgroundColor.stroke | The color of the chart border, as an HTML color string. Type: string Default: '#666' |
| backgroundColor.strokeWidth | The border width, in pixels. Type: number Default: 0 |
| backgroundColor.fill | The chart fill color, as an HTML color string. Type: string Default: 'white' |
| bar.groupWidth | The width of a group of bars, specified in either of these formats:
Type: number or string Default: Thegolden ratio, approximately '61.8%'. |
| bars | Whether the bars in aMaterial Bar Chart are vertical or horizontal. This option has no effect on Classic Bar Charts or Classic Column Charts. Type: 'horizontal' or 'vertical' Default: 'vertical' |
| chartArea | An 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: Type: object Default: null |
| chartArea.backgroundColor | Chart area background color. When a string is used, it can be either a hex string (e.g., '#fdc') or an English color name. When an object is used, the following properties can be provided:
Type: string or object Default: 'white' |
| chartArea.left | How far to draw the chart from the left border. Type: number or string Default: auto |
| chartArea.top | How far to draw the chart from the top border. Type: number or string Default: auto |
| chartArea.width | Chart area width. Type: number or string Default: auto |
| chartArea.height | Chart area height. Type: number or string Default: auto |
| chart.subtitle | ForMaterial Charts, this option specifies the subtitle. Only Material Charts support subtitles. Type: string Default: null |
| chart.title | ForMaterial Charts, this option specifies the title. Type: string Default: null |
| colors | The colors to use for the chart elements. An array of strings, where each element is an HTML color string, for example: Type: Array of strings Default: default colors |
| dataOpacity | The transparency of data points, with 1.0 being completely opaque and 0.0 fully transparent. In scatter, histogram, bar, and column charts, this refers to the visible data: dots in the scatter chart and rectangles in the others. In charts whereselecting data creates a dot, such as the line and area charts, this refers to the circles that appear upon hover or selection. The combo chart exhibits both behaviors, and this option has no effect on other charts. (To change the opacity of a trendline, see trendline opacity.) Type: number Default: 1.0 |
| enableInteractivity | Whether the chart throws user-based events or reacts to user interaction. If false, the chart will not throw 'select' or other interaction-based events (butwill throw ready or error events), and will not display hovertext or otherwise change depending on user input. Type: boolean Default: true |
| explorer | The This feature isexperimental and may change in future releases. Note: The explorer only works with continuous axes (such as numbers or dates). Type: object Default: null |
| explorer.actions | The Google Charts explorer supports three actions:
Type: Array of strings Default: ['dragToPan', 'rightClickToReset'] |
| explorer.axis | By default, users can pan both horizontally and vertically when the Type: string Default: both horizontal and vertical panning |
| explorer.keepInBounds | By default, users can pan all around, regardless of where the data is. To ensure that users don't pan beyond the original chart, use Type: boolean Default: false |
| explorer.maxZoomIn | The maximum that the explorer can zoom in. By default, users will be able to zoom in enough that they'll see only 25% of the original view. Setting Type: number Default: 0.25 |
| explorer.maxZoomOut | The maximum that the explorer can zoom out. By default, users will be able to zoom out far enough that the chart will take up only 1/4 of the available space. Setting Type: number Default: 4 |
| explorer.zoomDelta | When users zoom in or out, Type: number Default: 1.5 |
| focusTarget | 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:
In focusTarget 'category' the tooltip displays all the category values. This may be useful for comparing values of different series. Type: string Default: 'datum' |
| fontSize | The default font size, in pixels, of all text in the chart. You can override this using properties for specific chart elements. Type: number Default: automatic |
| fontName | The default font face for all text in the chart. You can override this using properties for specific chart elements. Type: string Default: 'Arial' |
| forceIFrame | Draws the chart inside an inline frame. (Note that on IE8, this option is ignored; all IE8 charts are drawn in i-frames.) Type: boolean Default: false |
| hAxes | Specifies properties for individual horizontal axes, if the chart has multiple horizontal axes. Each child object is a To specify a chart with multiple horizontal axes, first define a new axis using
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 hAxes: { {}, // Nothing specified for axis 0 { title:'Losses', textStyle: { color: 'red' } } // Axis 1Type: Array of object, or object with child objects Default: null |
| hAxis | 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' }}Type: object Default: null |
| hAxis.baseline | The baseline for the horizontal axis. Type: number Default: automatic |
| hAxis.baselineColor | The color of the baseline for the horizontal axis. Can be any HTML color string, for example: Type: number Default: 'black' |
| hAxis.direction | The direction in which the values along the horizontal axis grow. Specify Type: 1 or -1 Default: 1 |
| hAxis.format | A format string for numeric axis labels. This is a subset of the ICU pattern set. For instance,
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. In computing tick values and gridlines, several alternative combinations of all the relevant gridline options will be considered and alternatives will be rejected if the formatted tick labels would be duplicated or overlap. So you can specify Type: string Default: auto |
| hAxis.gridlines | An object with properties to configure the gridlines on the horizontal axis. Note that horizontal axis gridlines are drawn vertically. To specify properties of this object, you can use object literal notation, as shown here: {color: '#333', minSpacing: 20}Type: object Default: null |
| hAxis.gridlines.color | The color of the horizontal gridlines inside the chart area. Specify a valid HTML color string. Type: string Default: '#CCC' |
| hAxis.gridlines.count | The approximate number of horizontal gridlines inside the chart area. If you specify a positive number for Type: number Default: -1 |
| hAxis.gridlines.units | Overrides the default format for various aspects of date/datetime/timeofday data types when used with chart computed gridlines. Allows formatting for years, months, days, hours, minutes, seconds, and milliseconds. General format is: gridlines: { units: { years: {format: [/*format strings here*/]}, months: {format: [/*format strings here*/]}, days: {format: [/*format strings here*/]} hours: {format: [/*format strings here*/]} minutes: {format: [/*format strings here*/]} seconds: {format: [/*format strings here*/]}, milliseconds: {format: [/*format strings here*/]}, }}Additional information can be found inDates and Times. Type: object Default: null |
| hAxis.minorGridlines | An object with members to configure the minor gridlines on the horizontal axis, similar to the hAxis.gridlines option. Type: object Default: null |
| hAxis.minorGridlines.color | The color of the horizontal minor gridlines inside the chart area. Specify a valid HTML color string. Type: string Default: A blend of the gridline and background colors |
| hAxis.minorGridlines.count | The Type: number Default:1 |
| hAxis.minorGridlines.units | Overrides the default format for various aspects of date/datetime/timeofday data types when used with chart computed minorGridlines. Allows formatting for years, months, days, hours, minutes, seconds, and milliseconds. General format is: gridlines: { units: { years: {format: [/*format strings here*/]}, months: {format: [/*format strings here*/]}, days: {format: [/*format strings here*/]} hours: {format: [/*format strings here*/]} minutes: {format: [/*format strings here*/]} seconds: {format: [/*format strings here*/]}, milliseconds: {format: [/*format strings here*/]}, }}Additional information can be found inDates and Times. Type: object Default: null |
| hAxis.logScale |
Type: boolean Default: false |
| hAxis.scaleType |
Type: string Default: null |
| hAxis.textStyle | An object that specifies the horizontal axis text style. The object has this format: { color: <string>, fontName: <string>, fontSize: <number>, bold: <boolean>, italic: <boolean> } The Type: object Default: {color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>} |
| hAxis.textPosition | Position of the horizontal axis text, relative to the chart area. Supported values: 'out', 'in', 'none'. Type: string Default: 'out' |
| hAxis.ticks | Replaces the automatically generated X-axis ticks with the specified array. Each element of the array should be either a valid tick value (such as a number, date, datetime, or timeofday), or an object. If it's an object, it should have a The viewWindow will be automatically expanded to include the min and max ticks unless you specify a Examples:
Type: Array of elements Default: auto |
| hAxis.title |
Type: string Default: null |
| hAxis.titleTextStyle | An object that specifies the horizontal axis title text style. The object has this format: { color: <string>, fontName: <string>, fontSize: <number>, bold: <boolean>, italic: <boolean> } The Type: object Default: {color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>} |
| hAxis.maxValue | Moves the max value of the horizontal axis to the specified value; this will be rightward in most charts. Ignored if this is set to a value smaller than the maximum x-value of the data. Type: number Default: automatic |
| hAxis.minValue | Moves the min value of the horizontal axis to the specified value; this will be leftward in most charts. Ignored if this is set to a value greater than the minimum x-value of the data. Type: number Default: automatic |
| hAxis.viewWindowMode | Specifies how to scale the horizontal axis to render the values within the chart area. The following string values are supported:
Type: string Default: Equivalent to 'pretty', but haxis.viewWindow.min andhaxis.viewWindow.max take precedence if used. |
| hAxis.viewWindow | Specifies the cropping range of the horizontal axis. Type: object Default: null |
| hAxis.viewWindow.max | The maximum horizontal data value to render. Ignored when Type: number Default: auto |
| hAxis.viewWindow.min | The minimum horizontal data value to render. Ignored when Type: number Default: auto |
| height | Height of the chart, in pixels. Type: number Default: height of the containing element |
| isStacked | If set to true, stacks the elements for all series at each domain value.Note: InColumn,Area, andSteppedArea charts, Google Charts reverses the order of legend items to better correspond with the stacking of the series elements (E.g. series 0 will be the bottom-most legend item). This does notapply toBar Charts. The The options for
For 100% stacking, the calculated value for each element will appear in the tooltip after its actual value. The target axis will default to tick values based on the relative 0-1 scale as fractions of 1 for 100% stacking only supports data values of type Type: boolean/string Default: false |
| legend | 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}}Type: object Default: null |
| legend.pageIndex | Initial selected zero-based page index of the legend. Type: number Default: 0 |
| legend.position | Position of the legend. Can be one of the following:
Type: string Default: 'right' |
| legend.alignment | Alignment of the legend. Can be one of the following:
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'. Type: string Default: automatic |
| legend.textStyle | An object that specifies the legend text style. The object has this format: { color: <string>, fontName: <string>, fontSize: <number>, bold: <boolean>, italic: <boolean> } The Type: object Default: {color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>} |
| reverseCategories | If set to true, will draw series from bottom to top. The default is to draw top-to-bottom. Type: boolean Default: false |
| orientation | The orientation of the chart. When set to Type: string Default: 'horizontal' |
| series | 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:
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}}Type: Array of objects, or object with nested objects Default: {} |
| theme | A 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:
Type: string Default: null |
| title | Text to display above the chart. Type: string Default: no title |
| titlePosition | Where to place the chart title, compared to the chart area. Supported values:
Type: string Default: 'out' |
| titleTextStyle | An object that specifies the title text style. The object has this format: { color: <string>, fontName: <string>, fontSize: <number>, bold: <boolean>, italic: <boolean> } The Type: object Default: {color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>} |
| tooltip | 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}Type: object Default: null |
| tooltip.ignoreBounds | If set to Note: This only applies to HTML tooltips. If this is enabled with SVG tooltips, any overflow outside of the chart bounds will be cropped. SeeCustomizing Tooltip Content for more details. Type: boolean Default: false |
| tooltip.isHtml | If set to true, use HTML-rendered (rather than SVG-rendered) tooltips. SeeCustomizing Tooltip Content for more details. Note: customization of the HTML tooltip content via thetooltip column data role isnot supported by theBubble Chart visualization. Type: boolean Default: false |
| tooltip.showColorCode | If true, show colored squares next to the series information in the tooltip. The default is true when Type: boolean Default: automatic |
| tooltip.textStyle | An object that specifies the tooltip text style. The object has this format: { color: <string>, fontName: <string>, fontSize: <number>, bold: <boolean>, italic: <boolean> } The Type: object Default: {color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>} |
| tooltip.trigger | The user interaction that causes the tooltip to be displayed:
Type: string Default: 'focus' |
| trendlines | Displays trendlines on the charts that support them. By default, linear trendlines are used, but this can be customized with the Trendlines are specified on a per-series basis, so most of the time your options will look like this: var options = { trendlines: { 0: { type: 'linear', color: 'green', lineWidth: 3, opacity: 0.3, showR2: true, visibleInLegend: true } }}Type: object Default: null |
| trendlines.n.color | The color of the trendline, expressed as either an English color name or a hex string. Type: string Default: default series color |
| trendlines.n.degree | For trendlines of Type: number Default: 3 |
| trendlines.n.labelInLegend | If set, the trendline will appear in the legend as this string. Type: string Default: null |
| trendlines.n.lineWidth | The line width of the trendline, in pixels. Type: number Default: 2 |
| trendlines.n.opacity | The transparency of the trendline, from 0.0 (transparent) to 1.0 (opaque). Type: number Default: 1.0 |
| trendlines.n.pointSize | Trendlines are constucted by stamping a bunch of dots on the chart; this rarely-needed option lets you customize the size of the dots. The trendline's Type: number Default: 1 |
| trendlines.n.pointsVisible | Trendlines are constucted by stamping a bunch of dots on the chart. The trendline's Type: boolean Default: true |
| trendlines.n.showR2 | Whether to show the coefficient of determination in the legend or trendline tooltip. Type: boolean Default: false |
| trendlines.n.type | Whether the trendlines is Type: string Default: linear |
| trendlines.n.visibleInLegend | Whether the trendline equation appears in the legend. (It will appear in the trendline tooltip.) Type: boolean Default: false |
| vAxis | 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'}}Type: object Default: null |
| vAxis.baseline |
This option is only supported for a Type: number Default: automatic |
| vAxis.baselineColor | Specifies the color of the baseline for the vertical axis. Can be any HTML color string, for example: This option is only supported for a Type: number Default: 'black' |
| vAxis.direction | The direction in which the values along the vertical axis grow. By default, low values are on the bottom of the chart. Specify Type: 1 or -1 Default: 1 |
| vAxis.format | 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,
For date axis labels, this is a subset of the date formatting ICU pattern set. For instance, 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. In computing tick values and gridlines, several alternative combinations of all the relevant gridline options will be considered and alternatives will be rejected if the formatted tick labels would be duplicated or overlap. So you can specify This option is only supported for a Type: string Default: auto |
| vAxis.gridlines | An object with members to configure the gridlines on the vertical axis. Note that vertical axis gridlines are drawn horizontally. To specify properties of this object, you can use object literal notation, as shown here: {color: '#333', minSpacing: 20} This option is only supported for a Type: object Default: null |
| vAxis.gridlines.color | The color of the vertical gridlines inside the chart area. Specify a valid HTML color string. Type: string Default: '#CCC' |
| vAxis.gridlines.count | The approximate number of horizontal gridlines inside the chart area. If you specify a positive number for Type: number Default: -1 |
| vAxis.gridlines.units | Overrides the default format for various aspects of date/datetime/timeofday data types when used with chart computed gridlines. Allows formatting for years, months, days, hours, minutes, seconds, and milliseconds. General format is: gridlines: { units: { years: {format: [/*format strings here*/]}, months: {format: [/*format strings here*/]}, days: {format: [/*format strings here*/]}, hours: {format: [/*format strings here*/]}, minutes: {format: [/*format strings here*/]}, seconds: {format: [/*format strings here*/]}, milliseconds: {format: [/*format strings here*/]} }}Additional information can be found inDates and Times. Type: object Default: null |
| vAxis.minorGridlines | An object with members to configure the minor gridlines on the vertical axis, similar to the vAxis.gridlines option. This option is only supported for a Type: object Default: null |
| vAxis.minorGridlines.color | The color of the vertical minor gridlines inside the chart area. Specify a valid HTML color string. Type: string Default: A blend of the gridline and background colors |
| vAxis.minorGridlines.count | The minorGridlines.count option is mostly deprecated, except for disabling minor gridlines by setting the count to 0. The number of minor gridlines depends on the interval between major gridlines (see vAxis.gridlines.interval) and the minimum required space (see vAxis.minorGridlines.minSpacing). Type: number Default: 1 |
| vAxis.minorGridlines.units | Overrides the default format for various aspects of date/datetime/timeofday data types when used with chart computed minorGridlines. Allows formatting for years, months, days, hours, minutes, seconds, and milliseconds. General format is: gridlines: { units: { years: {format: [/*format strings here*/]}, months: {format: [/*format strings here*/]}, days: {format: [/*format strings here*/]} hours: {format: [/*format strings here*/]} minutes: {format: [/*format strings here*/]} seconds: {format: [/*format strings here*/]}, milliseconds: {format: [/*format strings here*/]}, }}Additional information can be found inDates and Times. Type: object Default: null |
| vAxis.logScale | If true, makes the vertical axis a logarithmic scale. Note: All values must be positive. This option is only supported for a Type: boolean Default: false |
| vAxis.scaleType |
Type: string Default: null |
| vAxis.textPosition | Position of the vertical axis text, relative to the chart area. Supported values: 'out', 'in', 'none'. Type: string Default: 'out' |
| vAxis.textStyle | An object that specifies the vertical axis text style. The object has this format: { color: <string>, fontName: <string>, fontSize: <number>, bold: <boolean>, italic: <boolean> } The Type: object Default: {color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>} |
| vAxis.ticks | Replaces the automatically generated Y-axis ticks with the specified array. Each element of the array should be either a valid tick value (such as a number, date, datetime, or timeofday), or an object. If it's an object, it should have a The viewWindow will be automatically expanded to include the min and max ticks unless you specify a Examples:
This option is only supported for a Type: Array of elements Default: auto |
| vAxis.title |
Type: string Default: no title |
| vAxis.titleTextStyle | An object that specifies the vertical axis title text style. The object has this format: { color: <string>, fontName: <string>, fontSize: <number>, bold: <boolean>, italic: <boolean> } The Type: object Default: {color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>} |
| vAxis.maxValue | Moves the max value of the vertical axis to the specified value; this will be upward in most charts. Ignored if this is set to a value smaller than the maximum y-value of the data. This option is only supported for a Type: number Default: automatic |
| vAxis.minValue | Moves the min value of the vertical axis to the specified value; this will be downward in most charts. Ignored if this is set to a value greater than the minimum y-value of the data. This option is only supported for a Type: number Default: null |
| vAxis.viewWindowMode | Specifies how to scale the vertical axis to render the values within the chart area. The following string values are supported:
This option is only supported for a Type: string Default: Equivalent to 'pretty', but vaxis.viewWindow.min andvaxis.viewWindow.max take precedence if used. |
| vAxis.viewWindow | Specifies the cropping range of the vertical axis. Type: object Default: null |
| vAxis.viewWindow.max |
Ignored when Type: number Default: auto |
| vAxis.viewWindow.min |
Ignored when Type: number Default: auto |
| width | Width of the chart, in pixels. Type: number Default: width of the containing element |
Methods
| Method | |
|---|---|
draw(data, options) | Draws the chart. The chart accepts further method calls only after the Return Type: none |
getAction(actionID) | Returns the tooltip action object with the requested Return Type: object |
getBoundingBox(id) | Returns an object containing the left, top, width, and height of chart element
Values are relative to the container of the chart. Call thisafter the chart is drawn. Return Type: object |
getChartAreaBoundingBox() | Returns an object containing the left, top, width, and height of the chart content (i.e., excluding labels and legend):
Values are relative to the container of the chart. Call thisafter the chart is drawn. Return Type: object |
getChartLayoutInterface() | Returns an object containing information about the onscreen placement of the chart and its elements. The following methods can be called on the returned object:
Call thisafter the chart is drawn. Return Type: object |
getHAxisValue(xPosition, optional_axis_index) | Returns the horizontal data value at Example: Call thisafter the chart is drawn. Return Type: number |
getImageURI() | Returns the chart serialized as an image URI. Call thisafter the chart is drawn. Return Type: string |
getSelection() | Returns an array of the selected chart entities. Selectable entities are bars, legend entries and categories. For this chart, only one entity can be selected at any given moment. Return Type: Array of selection elements |
getVAxisValue(yPosition, optional_axis_index) | Returns the vertical data value at Example: Call thisafter the chart is drawn. Return Type: number |
getXLocation(dataValue, optional_axis_index) | Returns the pixel x-coordinate of Example: Call thisafter the chart is drawn. Return Type: number |
getYLocation(dataValue, optional_axis_index) | Returns the pixel y-coordinate of Example: Call thisafter the chart is drawn. Return Type: number |
removeAction(actionID) | Removes the tooltip action with the requested Return Type: none |
setAction(action) | Sets a tooltip action to be executed when the user clicks on the action text. The Any and all tooltip actions should be set prior to calling the chart's Return Type: none |
setSelection() | Selects the specified chart entities. Cancels any previous selection. Selectable entities are bars, legend entries and categories. For this chart, only one entity can be selected at a time. Return Type: none |
clearChart() | Clears the chart, and releases all of its allocated resources. Return Type: none |
Events
For more information on how to use these events, seeBasic Interactivity,Handling Events, andFiring Events.
| Name | |
|---|---|
animationfinish | Fired when transition animation is complete. Properties: none |
click | Fired when the user clicks inside the chart. Can be used to identify when the title, data elements, legend entries, axes, gridlines, or labels are clicked. Properties: targetID |
error | Fired when an error occurs when attempting to render the chart. Properties: id, message |
legendpagination | Fired when the user clicks legend pagination arrows. Passes back the current legend zero-based page index and the total number of pages. Properties: currentPageIndex, totalPages |
onmouseover | Fired when the user mouses over a visual entity. Passes back the row and column indices of the corresponding data table element. A bar 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). Properties: row, column |
onmouseout | Fired when the user mouses away from a visual entity. Passes back the row and column indices of the corresponding data table element. A bar 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). Properties: 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 eventbefore you call the Properties: none |
select | Fired when the user clicks a visual entity. To learn what has been selected, call Properties: none |
Data policy
All code and data are processed and rendered in the browser. No data is sent to any server.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.