Monthly Archives: September 2013

Create Charts with jFreeChart

 jFreeChart Demo

jFreeChart Demo

This tutorial is all about creating graphs. There are several tools for generating graphs without any hassle. Programming a graph from scratch might little be  tricky as it also deals with some graphics. Using a tool or library reduces the development time a lot. So we gonna use an OpenSource chart tool named jFreeChart for Java development.

Creating a graph with jFreeChart is just a matter of entering the required graph data and a little piece of code. Therefore, as the CodeZone4 norm I just go ahead with a 3D bar graph implementation using jFreeChart.

You can find source code for other types of graph on the internet.

First download required JARs from jFreeChart and add them in your project’s classpath.

import org.jfree.chart.*;
import org.jfree.chart.renderer.category.*;
import org.jfree.chart.plot.*;
import java.awt.*;

public class Main {

public static void main(String[] args) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.setValue(3780, "A", "2008");
dataset.setValue(5000, "B", "2008");
dataset.setValue(6500, "A", "2009");
dataset.setValue(6000, "B", "2009");
dataset.setValue(9000, "A", "2010");
dataset.setValue(10000, "B", "2010");
JFreeChart chart = ChartFactory.createBarChart3D("Annual Income Analysis", "Year", "Income",
dataset, PlotOrientation.VERTICAL, true, true, false);
CategoryPlot p = chart.getCategoryPlot();
ChartFrame frame1 = new ChartFrame("Income Data", chart);
frame1.setSize(300, 300);

Leave a comment

Posted by on September 29, 2013 in Java



Develop Voice Applications with VoiceXML

voice xml

voice xml

Web pages consist of HTML that is rendered into a visible page by a Web browser. Similarly, a voice application consists of XML (VoiceXML, CCXML, or CallXML) which becomes an interactive voice application when processed by the Voxeo Corporation VoiceCenter network. All you need to do is write the application’s XML, map it to a phone number in the Voxeo Application Manager, and give it a call.

Sample vxml file

<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.0" xmlns="">

<form id="login">

<field name="phone_number" type="phone">
<prompt>Please say your complete phone number</prompt>

<field name="pin_code" type="digits">
<prompt>Please say your PIN code</prompt>

<submit next=""
namelist="phone_number pin_code"/>


Getting started with VoiceXML 2.0

Leave a comment

Posted by on September 15, 2013 in Miscellaneous



Simple CRUD with MongoDB and PHP



Today we gonna make our hands dirty with some MongoDB stuff. MongoDB is a no-SQL type, schema-less database. Such databases can be very useful in situations where there is much more user-generated content. You should understand where you use MongoDB or Apache CouchDB rather than traditional relational databases. You may want to google for getting more details about MongoDB if you gonna try this tutorial as a newbie.

First download and install MongoDB in your environment.

As we are trying this tutorial in PHP, you should download mongo driver for PHP also.

Edit php.ini so that it can load mongo driver. Add this line(in Windows)

Now we are good to go.

Run MongoDB server and start Mongo shell.

First you need to create a database and add a database user. If this is the first time you ‘re going to create a database user, first you need to create an admin user. Read documentation¬†for more details.

This tutorial is all about a simple CRUD application using MongoDB. In this application a blog post scenario is used for demonstrating CRUD operations. This scenario is very popular in MongoDB Hello World tutorials.

This tutorial does not include complete source code. You can download it here.

DB class

class DB {

const DBHOST = 'localhost';
const DBUSER = 'codezone4';
const DBPWD = '123';
const DBPORT = 27017;
const DBNAME = 'blog_db';

private static $instance;
public $connection;
public $databse;

private function __construct() {
$connection_string = sprintf('mongodb://%s:%s@%s:%d/%s', DB::DBUSER, DB::DBPWD, DB::DBHOST, DB::DBPORT, DB::DBNAME);
try {
$this->connection = new Mongo($connection_string);
$this->databse = $this->connection->selectDB(DB::DBNAME);
} catch (MongoConnectionException $e) {
throw $e;

static public function instantiate(){
$class = __CLASS__;
self::$instance = new $class;
return self::$instance;

public function get_collection($name){
return $this->databse->selectCollection($name);


Add New Post

include 'db.class.php';
$title = $_POST['title'];
$content = $_POST['content'];

if(!empty($title) && !empty($content)){

$mongo =  DB::instantiate();
$post_collection = $mongo->get_collection('posts');
$post = array(
'_id' => hash('sha1', time() . $title),
'title' => $title,
'content' => $content,
'created_on' => new MongoDate()
$post_id = $post_collection->insert($post,array('safe'=>TRUE));
Leave a comment

Posted by on September 11, 2013 in MongoDB



jQueryMobile with Google Map

jQueryMobile with Google Map

jQueryMobile with Google Map


This demo is based on jQuery UI plugin for Google Maps.

<!doctype html>
<html lang="en">
<title>jQuery mobile with Google maps</title>
<link rel="stylesheet" href="" />
<script src=""></script>
<script src=""></script>
<script type="text/javascript" src=""> </script>
<script type="text/javascript" src=""></script>
<script type="text/javascript">

var colombo = new google.maps.LatLng(26.5727,73.8390);
var delhi = new google.maps.LatLng(28.6100,77.2300);
mobileDemo = { 'center': '28.6100,77.2300', 'zoom': 12 };

function initialize() {
$('#map_canvas').gmap({ 'center':, 'zoom': mobileDemo.zoom, 'disableDefaultUI':false });
$('#map_canvas').gmap('addMarker', { 'position': delhi } );

$(document).on("pageinit", "#basic-map", function() {

$(document).on('click', '.add-markers', function(e) {
$('#map_canvas').gmap('addMarker', { 'position': colombo } );
<div id="basic-map" data-role="page">
<div data-role="header">
<h1><a data-ajax="false" href="#">jQuery mobile with Google</a></h1>
<a data-rel="back">Back</a>
<div data-role="content">
<div style="padding:1em;">
<div id="map_canvas" style="height:350px;"></div>
<a href="#" data-role="button" data-theme="b">Add Some More Markers</a>
1 Comment

Posted by on September 9, 2013 in jQueryMobile



Find Visitor’s IP address in PHP

Relying on $_SERVER[‘REMOTE_ADDR’] to find your client’s ip address is not always good. Looking for a wide solution?

Then use this function.

function get_ip() {
$ip = '';
else if($_SERVER['REMOTE_ADDR'])
$ip = '';

return $ip;
Leave a comment

Posted by on September 4, 2013 in PHP