Generate Pie, Bar, Line Charts using Google Chart API

Reporting tools have became so pervasive today that a lot of applications around today’s IT world has these types of tools that reports a lot of complex data in a simple and understandable way. Pie charts, Bar graph, Line charts have became a standard way of representing data in a good and understandable way.

There are lots of Reporting tools available that can be leverage to create such kind of charts. Google Chart API is one of such online tool that can be used to generate complex charts for visual data representation.

What is Google Chart API?

The Google Chart API is an extremely simple tool that lets you easily create a chart from some data and embed it in a webpage. You embed the data and formatting parameters in an HTTP request, and Google returns a PNG image of the chart. Many types of chart are supported, and by making the request into an image tag you can simply include the chart in a webpage.

Google had created these API’s for their internal use to generate charts in applications like finance. But soon they realised these API’s will be of great use and hence they launched Google Chart API.

Supported Charts

Currently following are the charts that are being supported by Google Charts API.

  1. Line Chart
  2. Pie Chart
  3. Bar Chart
  4. Radar Chart
  5. Venn Diagrams
  6. Scatter Plots
  7. Sparklines
  8. Maps
  9. Google-o-meter
  10. QR Codes

How does it works?

Google Chart API works by sending a HTTP request using URL. All what we have to do is to create a URL that specifies all arguments and other information and send it using HTTP. Google Chart will return us the image of the Chart that we requested.

Live Examples

Following are few examples in each of the Chart types that you can generate using Google Chart APIs.

Pie Chart

Hello World Pie Chart.

google-pie-chart-hello-world

Two dimensional pie chart.

Concentric pie charts.

Bar Charts

Horizontal bar chart, with stacked bars.

Vertical bar chart, with stacked bars.

Horizontal bar chart, with grouped bars.

Line Charts

Chart of type LC.

Line charts of type ls are also known as sparklines.

For charts of type lxy, a pair of data sets is required for each line.

Venn diagrams

Scatter plots

Radar charts

Maps

Google-o-meters

Get our Articles via Email. Enter your email address.

You may also like...

16 Comments

  1. Sun says:

    Can you make more examples with labels on the axis? I can’t seem to figure it out. I want to do line charts and label the x & y axis.

  2. Viral Patel says:

    Hi Sun,
    For adding labels to axis, you can use chxt and chxl parameters. For example to add labels to line chart following URL can be used.

    http://chart.apis.google.com/chart?chxt=x,y,r,x
    &chxl=0:|Jan|July|Jan|July|Jan|1:|0|50|100|2:|A|B|C|3:|2005|2006|2007
    &cht=lc&chd=s:cEAELFJHHHKUju9uuXUc&chco=76A4FB&chls=2.0&chs=200x125
    


    Refer http://code.google.com/apis/chart/labels.html#axis_labels for more details.

  3. mr.think says:

    how to create a line chart using google charts.I want to create a chart which value is more than 100 like http://chart.apis.google.com/chart?cht=lc&chs=200×125&chd=t:150,130,250,150,147,245,140,212 but google is not working.So can any one tell me how can i create this chart ??????

  4. Viral Patel says:

    Hi Mr.Think,
    Google Chart API will take input points less than or equal to 100. In your case you are trying to give values greater than 100 as you mention.
    I will suggest you to convert your values in percentage values % and than pass it in URL.
    For example if your input set is (50,90,120,150,80,95) than you can convert these values into %. Simplest way is to treat 150 as 100 and convert rest of the values accordingly.
    I know this sounds weird but it is pure math.. This is nt the only way to convert these values between 100 ranges. We have not considered Minimum value from the list. But this will work..

    Let me know if it works for you.

  5. Neema Patel says:

    Viral,
    I’m trying to graph a line chart with at least 9 bars and a label for each bar (the label could also run over the bar). Can the x axis be extended to accomodate the width I require to display all the bars?
    Thanks for such a great tool!
    Neema

  6. Neema Patel says:

    Figured it out, Thanks!

  7. Ankita says:

    Please tell me if there is any command which could be run on command line so that the bar graph is displayed

  8. Kjuly says:

    Thank u! I got what I want! :D

  9. Z says:

    How can I plot line graph using data from excel file?

  10. sawan says:

    How can we send array of values dynamically as parameters? Now you are passing hard coded values..? Looking forward for your response.

  11. vineeth says:

    Thanks a lot for this post….u save my day…

  12. Rk says:

    nice 1. I have another example to Draw Pie charts clustering on Google Maps, please visit http://www.etechpulse.com/2013/07/how-to-create-chart-on-google-maps.html

    Thanks

  13. ravindra says:

    hi, i want to have bar,line,column and pie chart in a single page with different data for eg. pie chart has data regarding total votes ina city where as line chart must have vote share for all political parties in a city . hence,
    pie chart- total votes & city name
    line chart- political party, votes and city name
    bar graph – previous votes vs current votes
    column graph – age of population and their votes.
    thank you in advance. please any idea regarding this requirement .
    all graphs must load at a time.

  14. ravindra says:

    hi, i want to have bar,line,column and pie chart in a single page with different data for eg. pie chart has data regarding total votes ina city where as line chart must have vote share for all political parties in a city . hence,
    pie chart- total votes & city name
    line chart- political party, votes and city name
    bar graph – previous votes vs current votes
    column graph – age of population and their votes.
    thank you in advance. please any idea regarding this requirement .
    all graphs must load at a time.

  15. sandeepm says:

    thank you so much nice

  16. Imran says:

    Please note that it is deprecated in 2012 and Google can withdraw it without notice.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.