My favorites | English | Sign in

Try Google Chrome's developer tools New!

Google Chart API

Chart Basics

This document describes the required format of Chart API URLs and lists the available parameters.

Table of Contents

Introduction

The Google Chart API returns a PNG-format image in response to a URL. Several types of image can be generated, including line, bar, and pie charts. For each image type, you can specify attributes such as size, colors, and labels.

All the images in this document were generated with the Chart API. To view the URL of any image, do the following:

  • if you are using Firefox, right-click and then select View Image or Properties.
  • if you are using Internet Explorer, right-click and then select Properties.

To make a URL easier to read, this document often shows it on multiple lines. When you are using the Google Chart API, you must supply a URL on a single line.

Back to top

URL format

Google Chart API URLs must be in the following format:

http://chart.apis.google.com/chart?<parameter 1>&<parameter 2>&<parameter n>

Parameters are separated using the ampersand character (&). You can specify as many parameters as you like, in any order. For example, the Chart API returns the following chart in response to the URL below:

Yellow pie chart

http://chart.apis.google.com/chart?
chs=250x100
&chd=t:60,40
&cht=p3
&chl=Hello|World

Where:

  • http://chart.apis.google.com/chart? is the Chart API's location.
  • & separates parameters.
  • chs=250x100 is the chart's size in pixels.
  • chd=t:60,40 is the chart's data.
  • cht=p3 is the chart's type.
  • chl=Hello|World is the chart's label.

You can include a Chart API image in an HTML document by embedding a URL within an <img> tag. When the webpage is displayed in a browser, the Chart API renders the image within the page. For example, the following <img> tag results in the same image as above:

<img src="http://chart.apis.google.com/chart?
chs=250x100
&amp;chd=t:60,40
&amp;cht=p3
&amp;chl=Hello|World
"
alt="Sample chart" />

When you embed a URL in an HTML <img> tag, take care to use the character entity reference &amp; in place of an ampersand (&).

Back to top

Required and optional parameters

You must provide at least the following parameters:

All other parameters are optional. Optional parameters by chart type are listed in the following table. Note that QR Codes are omitted as they have no optional parameters.

Parameter Bar chart Line chart Radar chart Scatter plot Venn diagram Pie chart Google-
o-meter
Maps
Chart colors Yes Yes Yes Yes Yes Yes Yes Yes
Solid fill Yes Yes Yes Yes Yes Yes Background only Background only
Data scaling Yes Yes Yes Yes Yes Yes Yes  
Linear gradient Yes Yes Yes Yes Yes Background only Background only New!  
Linear stripes Yes Yes Yes Yes Yes Background only Background only New!  
Chart title Yes Yes Yes Yes Yes Yes Yes New!  
Chart legend Yes Yes Yes Yes Yes Yes New! Yes New!  
Axis styles and labels Yes Yes Yes Yes        
Grid lines Yes Yes Yes Yes        
Shape markers Yes Yes Yes Yes        
Range markers Yes Yes Yes Yes        
Financial markers Yes Yes            
Line styles Yes Yes Yes          
Fill area Yes Yes Yes          
Bar width and spacing Yes              
Bar chart zero line Yes              
Pie chart and Google-o-meter labels           Yes Yes  

Back to top

Chart size

Specify chart size with chs=<width in pixels>x<height in pixels>

For example, chs=300x200 generates a chart 300 pixels wide and 200 pixels high.

The largest possible area for all charts except maps is 300,000 pixels. As the maximum height or width is 1000 pixels, examples of maximum sizes are 1000x300, 300x1000, 600x500, 500x600, 800x375, and 375x800.

For maps, the maximum size is 440 pixels wide by 220 pixels high.

Back to top