GChart and Google Chart API: easy solution for charts in PHP and HTML

Are you looking for easy solution to create any charts on your website? There are plenty solutions which offers chart creation. You could try a new library which will help you to implement Google Chart API to your PHP project.

Google Chart API is very easy way to create and display different charts on your website online. There are many other projects which will help you with Flash or more dynamic charts, but Google Chart API is simple enough and powerful at the same time. You can create different charts with it by using minimum of your skills. The only thing you have to know is HTML, or better say, you have to know how to write an URL.

How to work with Google Chart API?

Google Chart API could be used in any type of web projects. It doesn't need any server side solution like PHP or ASP.NET, it doesn't need any client side technology like Flash or JavaScript. Google Chart API creates charts as an image. And it is free, of course.

If you need to create a chart, you can construct it using a special URL. There is a sample from Google Chart API homepage:


Try to put the address above to your browser. You should see this pie chart:


So if you know how to construct the chart using the special URL, you are able to put it on your page using the HTML IMG tag with the URL as a source:

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

You should be able to use a visual editor on your website if you are using any content management system. There is no problem with it.

Google Chart API has a nice documentation and I highly recommend to read it. You will see how to create more types of graphs, how to work with axes and so.

GChart: PHP library for Google Chart API

There is a new object oriented PHP library which will help you to create a Google Chart API URL in your PHP projects. So you will be able to dynamically construct the chart's URL and keep your code synoptic. This library I write about is called GChart and can be found at SourceForge.

The chart mentioned above could be created with GChart using this simple way:

$pie3d=new GChart_Pie3D(250,100);
<img src="<?php echo $pie3d->get_image_string(); ?>" /> 

As you can see, there are only three lines of code. At first you have to create a new object of a given type and dimensions.The next steps will add axes. And the final step is to print the URL for this chart to the HTML code. Fast and simple. GChart support these chart types:

  • Pie Chart (including 2D-pie chart and 3D-pie chart)
  • Line Chart
  • Bar Chart (including vertical bar chart and horizontal bar chart)
  • Radar Chart
  • Scatter Plot Chart
  • Google-O-Meter Chart
  • QR-Code Chart