Hide

Bar Charts

Overview

Google bar charts are rendered in the browser using SVG or VML, whichever is appropriate for the user's browser. Like all Google charts, bar charts display tooltips when the user hovers over the data. For a vertical version of this chart, see the column chart.

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 the style role:

There are three different ways to choose the colors, and our data table showcases them all: RGB values, English color names, and a CSS-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

The style role lets you control several aspects of bar appearance with CSS-like declarations:

  • color
  • opacity
  • fill-color
  • fill-opacity
  • stroke-color
  • stroke-opacity
  • stroke-width

We don't recommend that you mix styles too freely inside a chart—pick a style and stick with it—but to demonstrate all the style attributes, here's a sampler:

The first two bars each use a specific color (the first with an English name, the second with an RGB value). No opacity was chosen, so the default of 1.0 (fully opaque) is used; that's why the second bar obscures the gridline behind it. In the third bar, an opacity of 0.2 is used, revealing the gridline. In the fourth bar, three style attributes are used: stroke-color and stroke-width to draw the border, and fill-color to specify the color of the rectangle inside. The rightmost bar additionally uses stroke-opacity and fill-opacity to choose opacities for the border and fill:

   function drawChart() {
      var data = google.visualization.arrayToDataTable([
        ['Year', 'Visitations', { role: 'style' } ],
        ['2010', 10, 'color: gray'],
        ['2010', 14, 'color: #76A7FA'],
        ['2020', 16, 'opacity: 0.2'],
        ['2040', 22, 'stroke-color: #703593; stroke-width: 4; fill-color: #C5A5CF'],
        ['2040', 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, legend labels, and labels in the tooltips. In this section, we'll see how to put labels inside (or near) the bars in a bar chart.

Let's say we wanted to annotate each bar with the appropriate chemical symbol. We can do that with the annotation 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, you might want to include them on the bars themselves:

This is a little more complicated than it should be, because we create a DataView to specify the annotation for each bar.

  <script type="text/javascript">
    google.load("visualization", "1", {packages:["corechart"]});
    google.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 a formatter and wrap it in a function like this:

      function getValueAt(column, dataTable, row) {
        return dataTable.getFormattedValue(row, column);
      }

Then we could call it with calc: getValueAt.bind(undefined, 1).

If the label is too big to fit entirely inside the bar, it's displayed outside:

Stacked bar charts

A stacked bar chart is a bar chart that places related values atop one another. It's 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 setting the isStacked option to true:

      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
      };

Creating Material bar charts

In 2014, Google announced guidelines intended to support a common look and feel across its properties and apps (such as Android apps) that run on Google platforms. We call this effort Material Design. We'll be providing "Material" versions of all our core charts; you're welcome to use them if you like how they look.

Creating a Material Bar Chart is similar to creating what we'll now call a "Classic" Bar Chart. You load the Google Visualization API (although with the 'bar' package instead of the 'corechart' package), define your datatable, and then create an object (but of class google.charts.Bar instead of google.visualization.BarChart).

Note: Material Charts will not work in old versions of Internet Explorer. (IE8 and earlier versions don't support SVG, which Material Charts require.)

Material Bar Charts have many small improvements over Classic Bar Charts, including an improved color palette, rounded corners, clearer label formatting, tighter default spacing between series, softer gridlines and titles (and the addition of subtitles).

<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1.1", {packages:["bar"]});
      google.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, options);
      }
    </script>
  </head>
  <body>
    <div id="barchart_material" style="width: 900px; height: 500px;"></div>
  </body>
</html>

The Material Charts are in beta. The appearance and interactivity are largely final, but the way options are declared is not. If you are converting a Classic Bar Chart to a Material Bar Chart, you'll want to replace this line:

chart.draw(data, options);

...with this:

chart.draw(data, google.charts.Bar.convertOptions(options));

Dual-X charts

Note: Dual-X axes are available only for Material charts (i.e., those with package bar).

Sometimes you'll want to display two series in a bar chart, with two independent x-axes: a top axis for one series, and a bottom axis for another:

Note that not only are our two x-axes labeled differently ("parsecs" versus "apparent magnitude") but they each have their own independent scales and gridlines. If you want to customize this behavior, use the hAxis.gridlines options.

In the code below, the axes and series options together specify the dual-X appearance of the chart. The series option specifies which axis to use for each ('distance' and 'brightness'; they needn't have any relation to the column names in the datatable). The axes option then makes this chart a dual-X chart, placing the 'apparent magnitude' axis on the top and the 'parsecs' axis on the bottom.

<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1.1", {packages:["bar"]});
      google.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: 900,
          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 id="dual_x_div" style="width: 900px; height: 500px;"></div>
  </body>
</html>

Top-X charts

Note: Top-X axes are available only for Material charts (i.e., those with package bar).

If you want to put the X-axis labels and title on the top of your chart rather than the bottom, you can do that in Material charts with the axes.x option:

<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1.1", {packages:["bar"]});
      google.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 id="top_x_div" style="width: 900px; height: 500px;"></div>
  </body>
</html>

Loading

The google.load package name is "corechart".

  google.load("visualization", "1", {packages: ["corechart"]});

For Material Bar Charts, the google.load package name is "bar".

  google.load("visualization", "1", {packages: ["bar"]});

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

  var chart = new google.visualization.BarChart(container);

For Material Bar Charts, the visualization's class name is google.charts.Bar.

  var chart = new google.charts.Bar(container);

Data format

Rows: Each row in the table represents a group of bars.

Columns:

  Column 0 Column 1 ... Column N
Purpose: Bar 1 values in this group ... Bar N values in this group
Data Type: number ... number
Role: domain data ... data
Optional column roles:

None

...

 

Configuration options

Name Type Default Description
animation.duration number 0 The duration of the animation, in milliseconds. For details, see the animation documentation.
animation.easing string '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.
animation.startup boolean false Determines if the chart will animate on the initial draw. If true, the chart will start at the baseline and animate to its final state.
annotations.alwaysOutside boolean false In Bar and Column charts, if set to true, draws all annotations outside of the Bar/Column.
annotations.boxStyle object null For charts that support annotations, the annotations.boxStyle object controls the appearance of the boxes surrounding annotations:
var options = {
  annotations: {
    boxStyle: {
      stroke: '#888',           // Color of the box outline.
      strokeWidth: 1,           // Thickness of the box outline.
      rx: 10,                   // x-radius of the corner curvature.
      ry: 10,                   // y-radius of the corner curvature.
      gradient: {               // Attributes for linear gradient fill.
        color1: '#fbf6a7',      // Start color for gradient.
        color2: '#33b679',      // Finish color for gradient.
        x1: '0%', y1: '0%',     // Where on the boundary to start and end the
        x2: '100%', y2: '100%', // color1/color2 gradient, relative to the
                                // upper left corner of the boundary.
        useObjectBoundingBoxUnits: true // If true, the boundary for x1, y1,
                                        // x2, and y2 is the box. If false,
                                        // it's the entire chart.
      }
    }
  }
};
  

This option is currently supported for area, bar, column, combo, line, and scatter charts. It is not supported by the Annotation Chart.

annotations.highContrast boolean true For charts that support annotations, 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 set annotations.highContrast to false and don't specify your own annotation color, Google Charts will use the default series color for the annotation:
annotations.textStyle object null For charts that support annotations, the annotations.textStyle object controls the appearance of the text of the annotation:
var options = {
  annotations: {
    textStyle: {
      fontName: 'Times-Roman',
      fontSize: 18,
      bold: true,
      italic: true,
      color: '#871b47',     // The color of the text.
      auraColor: '#d799ae', // The color of the text outline.
      opacity: 0.8          // The transparency of the text.
    }
  }
};
  

This option is currently supported for area, bar, column, combo, line, and scatter charts. It is not supported by the Annotation Chart.

axisTitlesPosition string '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.
backgroundColor string 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.stroke string '#666' The color of the chart border, as an HTML color string.
backgroundColor.strokeWidth number 0 The border width, in pixels.
backgroundColor.fill string 'white' The chart fill color, as an HTML color string.
bar.groupWidth number or string The golden ratio, approximately '61.8%'. The width of a group of bars, specified in either of these formats:
  • Pixels (e.g. 50).
  • Percentage of the available width for each group (e.g. '20%'), where '100%' means that groups have no space between them.
bars 'horizontal' or 'vertical' 'vertical' Whether the bars in a Material Bar Chart are vertical or horizontal. This option has no effect on Classic Bar Charts or Classic Column Charts.
chartArea Object null 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: chartArea:{left:20,top:0,width:'50%',height:'75%'}
chartArea.backgroundColor string or object 'white' 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:
  • stroke: the color, provided as a hex string or English color name.
  • strokeWidth: if provided, draws a border around the chart area of the given width (and with the color of stroke).
chartArea.left number or string auto How far to draw the chart from the left border.
chartArea.top number or string auto How far to draw the chart from the top border.
chartArea.width number or string auto Chart area width.
chartArea.height number or string auto Chart area height.
chart.subtitle string null For Material Charts, this option specifies the subtitle. Only Material Charts support subtitles.
chart.title string null For Material Charts, this option specifies the title.
colors Array of strings default colors The colors to use for the chart elements. An array of strings, where each element is an HTML color string, for example: colors:['red','#004411'].
dataOpacity number 1.0 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 where selecting 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.)
enableInteractivity boolean true 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 (but will throw ready or error events), and will not display hovertext or otherwise change depending on user input.
focusTarget string '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.

fontSize number automatic The default font size, in pixels, of all text in the chart. You can override this using properties for specific chart elements.
fontName string 'Arial' The default font face for all text in the chart. You can override this using properties for specific chart elements.
forceIFrame boolean false Draws the chart inside an inline frame. (Note that on IE8, this option is ignored; all IE8 charts are drawn in i-frames.)
hAxes Array of object, or object with child objects null

Specifies properties for individual horizontal axes, if the chart has multiple horizontal axes. Each child object is a hAxis object, and can contain all the properties supported by hAxis. These property values override any global settings for the same property.

To specify a chart with multiple horizontal axes, first define a new axis using series.targetAxisIndex, then configure the axis using hAxes. The following example assigns series 1 to the bottom axis and specifies a custom title and text style for it:

series:{1:{targetAxisIndex:1}}, hAxes:{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 hAxis object shown above:

hAxes:[
{}, // Nothing specified for axis 0
{title:'Losses',textStyle:{color: 'red'}} // Axis 1
]
hAxis Object null

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.baseline number automatic The baseline for the horizontal axis.
hAxis.baselineColor number 'black' The color of the baseline for the horizontal axis. Can be any HTML color string, for example: 'red' or '#00cc00'.
hAxis.direction 1 or -1 1 The direction in which the values along the horizontal axis grow. Specify -1 to reverse the order of the values.
hAxis.format string auto A 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.

hAxis.gridlines Object null

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}
hAxis.gridlines.color string '#CCC' The color of the horizontal gridlines inside the chart area. Specify a valid HTML color string.
hAxis.gridlines.count number 5 The number of horizontal gridlines inside the chart area. Minimum value is 2. Specify -1 to automatically compute the number of gridlines.
hAxis.gridlines.units object null 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 in Dates and Times.
hAxis.minorGridlines Object null An object with members to configure the minor gridlines on the horizontal axis, similar to the hAxis.gridlines option.
hAxis.minorGridlines.color string A blend of the gridline and background colors The color of the horizontal minor gridlines inside the chart area. Specify a valid HTML color string.
hAxis.minorGridlines.count number 0 The number of horizontal minor gridlines between two regular gridlines.
hAxis.minorGridlines.units object null 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*/]}
          months: {format: [/*format strings here*/]},
          months: {format: [/*format strings here*/]},
        }
      }
    
Additional information can be found in Dates and Times.
hAxis.logScale boolean false hAxis property that makes the horizontal axis a logarithmic scale (requires all values to be positive). Set to true for yes.
hAxis.textStyle Object {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>,
  bold: <boolean>,
  italic: <boolean> }

The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.

hAxis.textPosition string 'out'

Position of the horizontal axis text, relative to the chart area. Supported values: 'out', 'in', 'none'.

hAxis.ticks Array of elements auto

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 v property for the tick value, and an optional f property containing the literal string to be displayed as the label.

Examples:

  • hAxis: { ticks: [5,10,15,20] }
  • hAxis: { ticks: [{v:32, f:'thirty two'}, {v:64, f:'sixty four'}] }
  • hAxis: { ticks: [new Date(2014,3,15), new Date(2013,5,15)] }
  • hAxis: { ticks: [16, {v:32, f:'thirty two'}, {v:64, f:'sixty four'}, 128] }

hAxis.title string null hAxis property that specifies the title of the horizontal axis.
hAxis.titleTextStyle Object {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>,
  bold: <boolean>,
  italic: <boolean> }

The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.

hAxis.maxValue number automatic 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. hAxis.viewWindow.max overrides this property.
hAxis.minValue number automatic 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. hAxis.viewWindow.min overrides this property.
hAxis.viewWindowMode string Equivalent to 'pretty', but haxis.viewWindow.min and haxis.viewWindow.max take precedence if used.

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. This will cause haxis.viewWindow.min and haxis.viewWindow.max to be ignored.
  • 'maximized' - Scale the horizontal values so that the maximum and minimum data values touch the left and right of the chart area. This will cause haxis.viewWindow.min and haxis.viewWindow.max to be ignored.
  • 'explicit' - A deprecated option for specifying the left and right scale values of the chart area. (Deprecated because it's redundant with haxis.viewWindow.min and haxis.viewWindow.max.) Data values outside these values will be cropped. You must specify an hAxis.viewWindow object describing the maximum and minimum values to show.
hAxis.viewWindow Object null Specifies the cropping range of the horizontal axis.
hAxis.viewWindow.max number auto The maximum horizontal data value to render.
Ignored when hAxis.viewWindowMode is 'pretty' or 'maximized'.
hAxis.viewWindow.min number auto The minimum horizontal data value to render.
Ignored when hAxis.viewWindowMode is 'pretty' or 'maximized'.
height number height of the containing element Height of the chart, in pixels.
isStacked boolean false If set to true, stacks the elements in a series. Note: In Column, Area, and SteppedArea 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 not apply to Bar Charts.
legend Object null

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.position string 'right' Position of the legend. Can be one of the following:
  • 'bottom' - Below the chart.
  • 'left' - To the left of the chart, provided the left axis has no series associated with it. So if you want the legend on the left, use the option targetAxisIndex: 1.
  • 'in' - Inside the chart, by the top left corner.
  • 'none' - No legend is displayed.
  • 'right' - To the right of the chart. Incompatible with the vAxes option.
  • 'top' - Above the chart.
legend.alignment string automatic Alignment 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.textStyle Object {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>,
  bold: <boolean>,
  italic: <boolean> }

The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.

reverseCategories boolean false If set to true, will draw series from bottom to top. The default is to draw top-to-bottom.
orientation string 'horizontal' The orientation of the chart. When set to 'vertical', rotates the axes of the chart so that (for instance) a column chart becomes a bar chart, and an area chart grows rightward instead of up:
series Array 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:

  • annotations - An object to be applied to annotations for this series. This can be used to control, for instance, the textStyle for the series:
    series: {
      0: {
        annotations: {
          textStyle: {fontSize: 12, color: 'red' }
        }
      }
    }

    See the various annotations options for a more complete list of what can be customized.
  • color - The color to use for this series. Specify a valid HTML color string.
  • labelInLegend - The description of the series to appear in the chart legend.
  • 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.
  • 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}}
theme string null 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:
  • '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'}
title string no title Text to display above the chart.
titlePosition string '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.
titleTextStyle Object {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>,
  bold: <boolean>,
  italic: <boolean> }

The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.

tooltip Object null

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.isHtml boolean false If set to true, use HTML-rendered (rather than SVG-rendered) tooltips. See Customizing Tooltip Content for more details.

Note: customization of the HTML tooltip content via the tooltip column data role is not supported by the Pie Chart and Bubble Chart visualizations.

tooltip.showColorCode boolean automatic If 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.textStyle Object {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>,
  bold: <boolean>,
  italic: <boolean> }

The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.

tooltip.trigger string 'focus'

The user interaction that causes the tooltip to be displayed:

  • 'focus' - The tooltip will be displayed when the user hovers over the element.
  • 'none' - The tooltip will not be displayed.
  • 'selection' - The tooltip will be displayed when the user selects the element.
trendlines Object null

Displays trendlines on the charts that support them. By default, linear trendlines are used, but this can be customized with the trendlines.n.type option.

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
          }
        }
      }
  

trendlines.n.color string default series color The color of the trendline, expressed as either an English color name or a hex string.
trendlines.n.degree number 3 For trendlines of type: 'polynomial', the degree of the polynomial (2 for quadratic, 3 for cubic, and so on). (The default degree may change from 3 to 2 in an upcoming release of Google Charts.)
trendlines.n.labelInLegend string null If set, the trendline will appear in the legend as this string.
trendlines.n.lineWidth number 2 The line width of the trendline, in pixels.
trendlines.n.opacity number 1.0 The transparency of the trendline, from 0.0 (transparent) to 1.0 (opaque).
trendlines.n.pointSize number 1 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 trendlines lineWidth will usually be preferable.
trendlines.n.showR2 boolean false Whether to show the coefficient of determination in the legend or trendline tooltip.
trendlines.n.type string linear Whether the trendlines is 'linear' (the default), 'exponential', or 'polynomial'.
trendlines.n.visibleInLegend boolean false Whether the trendline equation appears in the legend. (It will appear in the trendline tooltip.)
vAxis Object null

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.baseline number automatic vAxis 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.

This option is only supported for a continuous axis.

vAxis.baselineColor number 'black' Specifies the color of the baseline for the vertical axis. Can be any HTML color string, for example: 'red' or '#00cc00'.

This option is only supported for a continuous axis.

vAxis.direction 1 or -1 1 The direction in which the values along the vertical axis grow. Specify -1 to reverse the order of the values.
vAxis.format string auto

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.

vAxis.gridlines Object null

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}

This option is only supported for a continuous axis.

vAxis.gridlines.color string '#CCC' The color of the vertical gridlines inside the chart area. Specify a valid HTML color string.
vAxis.gridlines.count number 5 The number of vertical gridlines inside the chart area. Minimum value is 2. Specify -1 to automatically compute the number of gridlines.
vAxis.gridlines.units object null 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 in Dates and Times.
vAxis.minorGridlines Object null 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 continuous axis.

vAxis.minorGridlines.color string A blend of the gridline and background colors The color of the vertical minor gridlines inside the chart area. Specify a valid HTML color string.
vAxis.minorGridlines.count number 0 The number of vertical minor gridlines between two regular gridlines.
vAxis.minorGridlines.units object null 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 in Dates and Times.
vAxis.logScale boolean false If true, makes the vertical axis a logarithmic scale Note: All values must be positive.

This option is only supported for a continuous axis.

vAxis.textPosition string 'out'

Position of the vertical axis text, relative to the chart area. Supported values: 'out', 'in', 'none'.

vAxis.textStyle Object {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>,
  bold: <boolean>,
  italic: <boolean> }

The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.

vAxis.ticks Array of elements auto

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 v property for the tick value, and an optional f property containing the literal string to be displayed as the label.

Examples:

  • vAxis: { ticks: [5,10,15,20] }
  • vAxis: { ticks: [{v:32, f:'thirty two'}, {v:64, f:'sixty four'}] }
  • vAxis: { ticks: [new Date(2014,3,15), new Date(2013,5,15)] }
  • vAxis: { ticks: [16, {v:32, f:'thirty two'}, {v:64, f:'sixty four'}, 128] }

This option is only supported for a continuous axis.

vAxis.title string no title vAxis property that specifies a title for the vertical axis.
vAxis.titleTextStyle Object {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>,
  bold: <boolean>,
  italic: <boolean> }

The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.

vAxis.maxValue number automatic 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. vAxis.viewWindow.max overrides this property.

This option is only supported for a continuous axis.

vAxis.minValue number automatic 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. vAxis.viewWindow.min overrides this property.

This option is only supported for a continuous axis.

vAxis.viewWindowMode string Equivalent to 'pretty', but vaxis.viewWindow.min and vaxis.viewWindow.max take precedence if used.

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. This will cause vaxis.viewWindow.min and vaxis.viewWindow.max to be ignored.
  • 'maximized' - Scale the vertical values so that the maximum and minimum data values touch the top and bottom of the chart area. This will cause vaxis.viewWindow.min and vaxis.viewWindow.max to be ignored.
  • 'explicit' - A deprecated option for specifying the top and bottom scale values of the chart area. (Deprecated because it's redundant with vaxis.viewWindow.min and vaxis.viewWindow.max. Data values outside these values will be cropped. You must specify a vAxis.viewWindow object describing the maximum and minimum values to show.

This option is only supported for a continuous axis.

vAxis.viewWindow Object null Specifies the cropping range of the vertical axis.
vAxis.viewWindow.max number auto
  • For a continuous axis:
    The maximum vertical data value to render.
  • 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.
Ignored when vAxis.viewWindowMode is 'pretty' or 'maximized'.
vAxis.viewWindow.min number auto
  • For a continuous axis:
    The minimum horizontal data value to render.
  • 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. Ignored when vAxis.viewWindowMode is 'pretty' or 'maximized'..
Ignored when vAxis.viewWindowMode is 'pretty' or 'maximized'.
width number width of the containing element Width of the chart, in pixels.

Methods

Method Return Type Description
draw(data, options) none Draws the chart. The chart accepts further method calls only after the ready event is fired. Extended description.
getAction(actionID) Object

Returns the tooltip action object with the requested actionID.

getBoundingBox(id) Object

Returns an object containing the left, top, width, and height of chart element id. The format for id isn't yet documented (they're the return values of event handlers), but here are some examples:

var cli = chart.getChartLayoutInterface();

Height of the chart area
cli.getBoundingBox('chartarea').height
Width of the third bar in the first series of a bar or column chart
cli.getBoundingBox('bar#0#2').width
Bounding box of the fifth wedge of a pie chart
cli.getBoundingBox('slice#4')
Bounding box of the chart data of a vertical (e.g., column) chart:
cli.getBoundingBox('vAxis#0#gridline')
Bounding box of the chart data of a horizontal (e.g., bar) chart:
cli.getBoundingBox('hAxis#0#gridline')

Values are relative to the container of the chart. Call this after the chart is drawn.

getChartAreaBoundingBox() Object

Returns an object containing the left, top, width, and height of the chart content (i.e., excluding labels and legend):

var cli = chart.getChartLayoutInterface();

cli.getChartAreaBoundingBox().left
cli.getChartAreaBoundingBox().top
cli.getChartAreaBoundingBox().height
cli.getChartAreaBoundingBox().width

Values are relative to the container of the chart. Call this after the chart is drawn.

getChartLayoutInterface() Object

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:

  • getBoundingBox
  • getChartAreaBoundingBox
  • getHAxisValue
  • getVAxisValue
  • getXLocation
  • getYLocation

Call this after the chart is drawn.

getHAxisValue(position, optional_axis_index) Number

Returns the logical horizontal value at position, which is an offset from the chart container's left edge. Can be negative.

Example: chart.getChartLayoutInterface().getHAxisValue(400).

Call this after the chart is drawn.

getImageURI() String

Returns the chart serialized as an image URI.

Call this after the chart is drawn.

See Printing PNG Charts.

getSelection() Array of selection elements 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. Extended description .
getVAxisValue(position, optional_axis_index) Number

Returns the logical vertical value at position, which is an offset from the chart container's top edge. Can be negative.

Example: chart.getChartLayoutInterface().getVAxisValue(300).

Call this after the chart is drawn.

getXLocation(position, optional_axis_index) Number

Returns the screen x-coordinate of position relative to the chart's container.

Example: chart.getChartLayoutInterface().getXLocation(400).

Call this after the chart is drawn.

getYLocation(position, optional_axis_index) Number

Returns the screen y-coordinate of position relative to the chart's container.

Example: chart.getChartLayoutInterface().getYLocation(300).

Call this after the chart is drawn.

removeAction(actionID) none Removes the tooltip action with the requested actionID from the chart.
setAction(action) none

Sets a tooltip action to be executed when the user clicks on the action text.

The setAction method takes an object as its action parameter. This object should specify 3 properties: id— the ID of the action being set, text —the text that should appear in the tooltip for the action, and action — the function that should be run when a user clicks on the action text.

Any and all tooltip actions should be set prior to calling the chart's draw() method. Extended description.

setSelection() none 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. Extended description .
clearChart() none Clears the chart, and releases all of its allocated resources.

Events

For more information on how to use these events, see Basic Interactivity, Handling Events, and Firing Events.

Name Description Properties
animationfinish Fired when transition animation is complete. 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. targetID
error Fired when an error occurs when attempting to render the chart. id, message
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). 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). 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 visual entity. To learn what has been selected, call getSelection(). None

Data policy

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