Showing posts with label Google Chart API. Show all posts
Showing posts with label Google Chart API. Show all posts

Saturday, October 15, 2011

Generating QR code by Google Chart API


Google provide lots of API for developers to develop their own tools. Today I would like to go through a funny feature from Google Chart Tools - QR code generating.


Developer always have to come across with tons of data and make it to a presentable report for end-users. Google Chart Tools can save your a day. However, we just focus on QR code generating function today. If you interest in it, check it out at http://code.google.com/apis/chart/.


Generating QR code by Google API is just a piece of cake. You just have to append your target message to a URL. Here is an example.


I want to make a QR code with a message 'We love programming.', here we go
https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=We%20love%20programming


Actually it will be a image if you click on it. The parameter chs is widthxheight. Parameter chl is the message or URL you want to include. Please do URL encode for your message.


I have written a snippet of code to generate QR code by current URL automatically.

<div id="qrcode"></div>
<script>
var img = document.createElement('img');
img.src = 'https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=' + encodeURIComponent(document.location.href);
document.getElementById('qrcode').appendChild(img);
</script>



Here is just the core function. You can also design your own interface to make a nice QR code generator. For more details, check out the document of Google, http://code.google.com/apis/chart/infographics/docs/overview.html

You can build QR code easily with Google Chart API now, but how QR code can help on your business? Try to read this:
Related Posts Plugin for WordPress, Blogger...