10/27/12

Data Warehousing Object: Dimension Tables Types

We had our last post on Fact Tables in Data Warehousing. This post is on Dimension Table Types. Along with Fact Tables there are many types of Dimension Tables which are used in Data Warehousing.

Dimension Tables are those tables which contain attributes that helps in describing the facts of the fact table.

The following are types of Dimension Tables:

* Slowly Changing Dimensions
* Junk Dimensions
* Confirmed Dimensions
* Degenerated Dimensions


10/12/12

Creating and using String Variables in visual basic

In today's tutorial I am going to be showing you how to declare and use string variables in visual basic 2010. The very basics of what you need to know about string variables are it will store a string of characters with a label name which you can then call upon later on in your programme. This can save you time as it reduces the amount of code you will have to write.


9/26/12

Data Warehousing Object : Fact Tables

In the previous post on DW we saw different types of Data Warehousing Schemas. So the different types of schemas had one thing in common and that was, they had Fact and Dimension Tables. So these are nothing but Data Warehousing Objects. 

Apart from Fact Tables, Dimension Tables there are other things which come under Data Warehousing Objects, they are:

* Fact Tables
* Dimension Tables
* Hierarchies
* Unique Identifiers
* Relationships

In today's post we will be taking a look in Fact tables.

9/22/12

I want my KAJU KATLI. Do you?

An off the topic post on Code 2 Learn, as KAJU KATLI made me go WOW!!. 

You all might be thinking why am I referring to KAJU KATLI and why am I saying "I want my KAJU KATLI"

A friend of mine, who is an entrepreneur, a blogger and a creative genius did some research on Google's Android OS naming convention. We all at Code 2 Learn are very aware of the naming conventions in programming languages, but we never noticed that Google also follows a certain pattern to name its Android OS. 


9/16/12

Count the number of lines in a File in UNIX

UNIX doesn't have any real command which helps us to get the number of lines which has records or data in it. But what UNIX offers is to get the number of new lines.

The command wc -l <file_name> gives us the number of new line characters and not the no. of lines which has data. For Example, in UNIX make a file, open it and then press enter (dont write anything). Now for the same file run the above command, you will find that it returns an output as 1, which is wrong as it should return 0 as the file has no data in it.

Therefore, to overcome this shortcoming of wc -l, I thought of writing a Shell script which will give us the exact count of the number lines which has data in it.


9/15/12

Data Warehousing SCHEMAS

A schema is a collection of database objects, including table, views, indexes and synonyms.

There are some special architectures which arranges the schema objects in the schemas models. The most common of them are :

* Star Schema
* Snowflake Schema
* Fact constellation Schema


9/4/12

8/19/12

Iterative Statements in PL/SQL

In the last post on PL/SQL, we had seen Conditional Statements and how they can be used. Today we will be learning about Iterative Statements in PL/SQL.


As we all know the types of Iterative statements that are there in a programming language. PL/SQL also has the same iterative statements and the functioning is also the same, but the only thing different is their syntax


So lets not waste any time and move on to the topic.



UNIX and SHELL Scripting : General Purpose Commands

As everyone is aware of UNIX nowadays thanks to UBUNTU, which has made this platform very popular.

In this post we won't be learning about UNIX or its architecture but what we will be learning are the General Purpose Commands required for UNIX and SHELL Scripting.

UNIX has a lot of commands which perform different functions, and also it has different types of SHELLS like BASH, KORN SHELL. All the shells in unix has some or the other limitation on commands.

So we are considering our shell as BASH, as we all work in BASH shell normally.


7/25/12

7/6/12

GROUP BY vs DISTINCT in SQL

This question has to come my mind many times and also I have been asked the same question many time. That what should be used GROUP BY or DISTINCT, as both perform the same thing.


So, after researching and using both statements and checking the performance using some scripts from here and there, I have come to the conclusion that GROUP BY performs much better then DISTINCT.

Now before, we move on to more discussion, lets first understand what does actually both do.


6/30/12

Variables and Constants in PL/SQL

This is out first of many tutorial in the PL/SQL series. Today we will be discussing about variables and coonstants in PL/SQL.

PL/SQL stands for Procedural Language to Structured Query Language. We can use PL/SQL in the Oracle relational databases, in Oracle Server, and in client-side application development tools, such as Oracle Forms.

PL/SQL has features such as : 
* Data abstraction
* Data encapsulation
* Object-Orientation
* Exception-handling.

We will be using Oracle 9i, in our tutorials for PL/SQL.



6/26/12

SQL Data Control Language (DCL) Tutorial

After doing tutorials on DML (Data Manipulation Language) and DDL (Data Definition Language), we will be learning about one more language used in SQL called the Data Control Language (DCL).

As we saw in our previous tutorials on SQL, that with the help of DDL we can define tables, databases, views etc in SQL and with the help of DML we can manipulate those existing tables, views etc. So apart from these there are other language(s) like the DCL which help us to give or take rights to a user. 

Basically, DCL is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.

The DCL commands that helps in achieving the above are GRANT and REVOKE.

Only Database Administrator's or owner's of the database object can provide/remove privileges on a databse object.


6/23/12

SQL Data Definition Language (DDL) Tutorial

After writing a post on Data Manipulation Language (DML), here is another tutorial in SQL series on DDL i.e. Data Definition Language.

DDL (Data Definition Language) statements are used to build and modify the structure of your tables and other objects in the database. When you execute a DDL statement, it takes effect immediately. Some of the DDL commands are CREATE, ALTER, DROP, USE. 

* Another DDL statement is used to define the referential integrity, which we will see later in the tutorial.


6/15/12

SQL Tutorial on Data Manipulation Language (DML)

After writing a tutorial on SQL Baiscs, long back, here I am writing again on SQL, but this time on DML i.e. Data Manipulation Language.

By the full form of DML we understand that with the help of this we will be able to manipulate data. Now what kind of manipulation can we do might be the next question in your mind, so SQL supports manipulation like INSERT, UPDATE, DELETE and MERGE


6/10/12

Creating Intricate Animation Effects Using JavaScript / JQuery

This tutorial will provide you with professional flip and rotation effects that can appear to spin an object around to reveal the opposite side or rotate the image. Three different spin effects will be provided as well as a few rotation effects, making this a great way to increase the aesthetic value of your web pages. This method takes two objects and then animates them so that they appear to flip over as if they are attached back to back. It requires these arguments:

               
id1 : An object or object ID -it may not be an array                            
id2 : An object or object ID - it may not be an array
w : If true or 1, the width will be flipped
: If true or 1, the height will be flipped
msecs : The number of milliseconds the flip should take                
pad : If set, the objects will be padded to retain their overall dimensions during the flip                        


6/3/12

Creating a Basic JDBC application

Today we will be creating a Basic JDBC application i.e. an application that will be able to retrieve information (student_name, roll_no, class, DOB, etc) from the database. I already gave a tutorial on connecting SQL Server using JDBC-ODBC Bridge.

To do the above we will need to make use of the JDBC-ODBC Bridge driver. And also the following task will also be done :

* Create a Data Source Name (DSN)
* Code the Application
* Compile and Execute the Application

And for the first time I will be showing on Code 2 Learn how to compile and run a java program from the command promt.


5/21/12

Starting with CodeIgniter : Hello World App.

CodeIgniter is an open source web application framework built for PHP coders who want to develop a full-feature web application. It has libraries which help us to perform many tasks very easily. It works on the MVC Pattern.


Model–View–Controller (MVC) is a design pattern for computer user interfaces that divides an application into three areas of responsibility:
  1. the Model : the data structures that represent the application's state.
  2. the View : which observes the state and generates output to the users.
  3. the Controller : which translates user input into operations on the model.


5/20/12

Transaction Isolation Levels in JDBC

The transaction isolation levels in JDBC help us to determine whether the concurrently running transactions in a DB can affect each other or not. If there are 2 or more transactions concurrently accessing the same DataBase, then we need to prevent the actions of the transactions from interfering with each other.

The above is achieved using the isolation levels in JDBC. 




5/9/12

PHP Operators

Fighting With PHP operators:



In all programming languages, operators play a key role in performing tasks with variables and values. You might have knowledge about "." or assignment operator"=".


There are many operators in PHP. Here these are categorized as :

  1. Assignment Operators
  2. Arithmetic Operators
  3. Comparison Operators
  4. String Operators
  5. Increment / Decrement Operators
Here, i will shed light on each of them with a code example. so let us go


5/7/12

A Tutorial on Arrays in PHP

Arrays in all languages whether Java, C++, Python, C etc are the same. 


Definition, Arrays are complex variables that store a group of values under a single variable name.



Creating Arrays


Its difficult for a person who is new to PHP to create an array, because arrays every language is created differently though they do the the same thing. This was a problem which I also had initially when I started coding in php.



5/5/12

Algorithm Tutorials - Part 1 : Ad-Hoc Problems

I will start with the very basic of Algorithms.

Before moving on to the different algorithms, let's first see what does an algorithm actually mean?



Definition


A process or set of rules to be followed in calculations or other problem-solving operations, esp. by a computer.  


Aho, Hopcroft and Ullman, had stated in their book on algorithms, named, "The Design and Analysis of Computer Algorithms" that "Perhaps the most important principle for the good algorithm designer is to refuse to be content."



5/2/12

Cloud Computing : The Future of Web

This is not a tutorial with codes, its a tutorial to make people aware about Cloud Computing, later posts will have tutorials with examples of App Engine. Before we move into Cloud Computing and its characteristics. Lets take the word cloud.

CLOUD


Cloud is a place or an area where we have all the components of cloud computing, basically its a metaphor for the Internet. By components I mean Server (Application/Back-up), Database, Back-up Storage, Network etc. 


4/19/12

Object-Oriented Programming meets PHP with examples

After getting request for the above topic, we decided to write a tutorial on it. However, if you need more detailed lessons you can check out www.computerclasses.org for available courses on this topic.

As we all know that object-oriented programming is an approach in which objects and classes are used and this approach is being followed by the some of the leading programming language like C++ and Java. Click here, to read about OOPs Concept in Java.

Before the introduction of PHP 4 OOP in PHP was not at all possible but after its introduction in PHP 4 and more advancement in PHP 5, the users are making full use of it and other programmer who thought PHP to be difficult are now actually enjoying it.



4/17/12

4/13/12

Querying Data using the PreparedStatement Object

Consider a scenario where a New Publishers, a pubhlishing company maintains information about the books and the authors in a database. The company wants an application using which they cab access the information about authors based on different criteria. For Example, it should retain all authors living in a city specified at runtime. In this scenario, we cannot use Statement object to retrieve information because the value needs to be specified at the runtime. We need to use the PreparedStatement object as it can accept runtime parameters.

The PreparedStatement interface is derived from Statement interface and  is available in the java.sql package. 

The PreparedStatement objects are compiled and prepared only once by JDBC.


Using HighCharts with php, MySQL and CodeIgniter

Highcharts is a charting library which helps to display interactive Javascript charts on webpages. But our tutorial is how to make use of Highcharts with php, MySQL and CodeIgniter. 

While working on a project I found out that HighCharts is the best to display graphs on webpage as it has less overhead and requires less space. But the biggest challenge was to implement it using php  and not jQuery. We will implement it using MVC pattern as CodeIgniter follows the same.

Here is how we will be going about leaning this :

1. We will need HighCharts Library for CodeIgniter and HighChart config file. That we have defined below. (library is pretty long)
2. We will be making Models, Controllers and Views to display the Chart taking the values from MySQL. (if you want to check controllrt, model and view then directly go to the end)

So before we go ahead you will need to download the Javascript file of HighChart. Click Here (downloasd HighChart and not HighStock)

Below is the library and config file that you will need to COPY & PASTE  to a .php file. Name the librayr file as HighCharts_lib.php and config file as HighCharts_config.php.

HighChart Library for CodeIgniter

Below is the library file, you will need to put this 

HighChart_lib.php : 


<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Highcharts {
    
    private static $chart_id = 0;
    
    private $shared_opts     = array(); // shared grah data
    private $global_opts    = array(); // All stocked graph data
    private $opts                    = array(); // current graph data
    private $replace_keys, $orig_keys, $serie_index = 0;
    
    public $js_chart_name = 'chart'; // name of the js var    
    
    public function __construct($config = array())
    {                
        if (count($config) > 0) $this->initialize($config);
    }
    
    public function initialize($config = array(), $config_path = 'highcharts')
    {
        if (is_string($config)) // string means "load this template"
        {
            $ci =& get_instance();
            $ci->config->load($config_path);
            
            $config = $ci->config->item($config);
            
            if (count($config) > 0)
            {
                $this->opts = $this->set_local_options($config);
            }
            
        }
        if (isset($config['shared_options']) AND empty($this->shared_opts))
        {
            $this->shared_opts = $config['shared_options'];
            unset($config['shared_options']);
        }
        
        if (! isset($this->opts['series'])) $this->opts['series'] = array();
        if (! isset($this->opts['chart']['renderTo'])) 
            $this->opts['chart']['renderTo'] = 'hc_chart';

        return $this;
    }

    public function set_global_options($options = array())
    {
        if (! empty($options)) 
            $this->shared_opts = $this->set_local_options($options);
        
        return $this;
    }

    public function __call($func, $args)
    {
        if (strpos($func,'_'))
        {
            list($action, $type) = explode('_', $func);
        
            if (! isset($this->opts[$type]))
            {
                $this->opts[$type] = array();
            }
            switch ($action)
            {
                case 'set':
                $this->opts[$type] = $this->set_local_options($args[0]);
                break;
                
                case 'push':
                $this->opts[$type] += $this->set_local_options($args[0]);
                break;
                
                case 'unset':
                $this->unset_local_options($args, $type);
                break;
            }
        }
        
        return $this;
    }
    
    private function set_local_options($options = array(), $root = array())
    {
        foreach ($options as $opt_key => $opt_name)
        {        
            if(is_string($opt_key))
            {
                if(is_object($opt_name))
                {
                    $root[$opt_key] = array();
                    $root[$opt_key] = 
                    $this->set_local_options($opt_name, $root[$opt_key]); 
                }
                else $root[$opt_key] = $this->encode_function($opt_name);
            }
        }
        return $root;
    }
    
    private function unset_local_options($options = array(), $type)
    {        
        foreach ($options as $option)
        {
            if (array_key_exists($option, $this->opts[$type]))
            {
                unset($this->opts[$type][$option]);
            }
        }
    }
    
    public function set_title($title = '', $subtitle = '')
    {
        if ($title) $this->opts['title']['text'] = $title;
        if ($subtitle) $this->opts['subtitle']['text'] = $subtitle;

        return $this;
    }
    
    function set_axis_titles($x_title = '', $y_title = '')
    {
        if ($x_title) $this->opts['xAxis']['title']['text'] = $x_title;
        if ($y_title) $this->opts['yAxis']['title']['text'] = $y_title;
        
        return $this;
    }

     function set_axis_ymax( $y_max)
    {
        if ($y_max) $this->opts['yAxis']['max'] = $y_max;

        return $this;
    }

     function set_axis_ymin( $y_min)
    {
        if ($y_min) $this->opts['yAxis']['min'] = $y_min;

        return $this;
    }

     function set_axis_ytype( $type = '')
    {
        If($type and is_string($type)) $this->opts['yAxis']['type'] = $type;

        return $this;
    }

                
     function set_axis_xtype( $type = '')
    {
        If($type and is_string($type)) $this->opts['xAxis']['type'] = $type;

        return $this;
    }

     function set_axis_xmax($x_max)
    {
        if ($x_max) $this->opts['xAxis']['max'] = $x_max;

        return $this;
    }
    
    public function render_to($id = '')
    {
        $this->opts['chart']['renderTo'] = $id;

        return $this;
    }
    
    public function set_type($type = '')
    {
        if ($type AND is_string($type)) $this->opts['chart']['type'] = $type;
        
        return $this;
    }
    
    
    public function set_dimensions($width = null, $height = null)
    {
        if ($width)  $this->opts['chart']['width'] = (int)$width;
        if ($height) $this->opts['chart']['height'] = (int)$height;
        
        return $this;
    }
    
    public function set_serie($options = array(), $serie_name = '')
    {
        if ( ! $serie_name AND ! isset($options['name']))
        {
            $serie_name = count($this->opts['series']);
        }
        // override with the serie name passed
        else if ($serie_name AND isset($options['name']))
        {
            $options['name'] = $serie_name;
        }
        
        $index = $this->find_serie_name($serie_name);
                    
        if (count($options) > 0)
        {
            foreach($options as $key => $value)
            {
                    $value = (is_numeric($value)) ? (float)$value : $value;
                    $this->opts['series'][$index][$key] = $value;
            }
        }
        return $this;
    }
    
    public function set_serie_options($options = array(), $serie_name = '')
    {
        if ($serie_name AND count($options) > 0)
        {
            $index = $this->find_serie_name($serie_name);
                        
            foreach ($options as $key => $opt)
            {
                $this->opts['series'][$index][$key] = $opt;
            }
        }
        return $this;
    }
    
    
    public function push_serie_data($value = '', $serie_name = ''){
        
        if ($serie_name AND $value)
        {
            $index = $this->find_serie_name($serie_name);
            
            $value = (is_numeric($value)) ? (float)$value : $value;
                
            $this->opts['series'][$index]['data'][] = $value;
        }
        return $this;
    }
    
    private function find_serie_name($name)
    {
        $tot_indexes = count($this->opts['series']);
        
        if ($tot_indexes > 0)
        {
            foreach($this->opts['series'] as $index => $serie)
            {
                if (isset($serie['name']) AND 

                    strtolower($serie['name']) == strtolower($name))
                {
                    return $index;
                }
            }
        }
        
        $this->opts['series'][$tot_indexes]['name'] = $name;
        
        return $tot_indexes;
    }

     public function export_file($filename){
         $this->opts['exporting']['enabled'] = True;
         $this->opts['exporting']['enableImages'] = True;
         $this->opts['exporting']['filename'] = $filename;
         $this->opts['exporting']['type']=  'image/jpeg';
         return $this;
        }
    
    public function push_categorie($value, $axis = 'x')
    {
        if(trim($value)!= '') 
           $this->opts[$axis.'Axis']['categories'][] = $value;

        return $this;
    }

         public function push_xcategorie($value)
    {

          $this->opts['xAxis']['categories'] = $value;

        return $this;
    }    

    public function from_result($data = array())
    {
        if (! isset($this->opts['series']))
        {
            $this->opts['series'] = array();
        }
                
        foreach ($data['data'] as $row)
        {
            if (isset($data['x_labels'])) 
                $this->push_categorie($row->$data['x_labels'],'x');
            if (isset($data['y_labels'])) 
                $this->push_categorie($row->$data['y_labels'],'y');
            
            foreach ($data['series'] as $name => $value)
            {    
                // there is no options, juste assign name / value pair
                if (is_string($value))
                {
                    $text = (is_string($name)) ? $name : $value;
                    $dat  = $row->$value;
                }
                
                // options are passed
                else if (is_array($value))
                {
                    if (isset($value['name']))
                    {
                        $text = $value['name'];
                        unset($value['name']);
                    }
                    else
                    {
                        $text = $value['row'];
                    }
                    $dat = $row->{$value['row']};
                    unset($value['row']);
                    
                    $this->set_serie_options($value, $text);
                }
                
                $this->push_serie_data($dat, $text);
            }
        }
        return $this;
    }
    
    public function add($options = array(), $clear = true)
    {
        if (count($this->global_opts) <= 
            self::$chart_id AND ! empty($this->opts['series']))
        {
            if (is_string($options) AND trim($options) !== '')
            {
                $this->global_opts[$options] = $this->opts;
            }
            else
            {
                $this->global_opts[self::$chart_id] = 
                (count($options)> 0) ? $options : $this->opts;
            }
        }
        
        self::$chart_id++;    
        
        if ($clear === true) $this->clear();
                    
        return $this;
    }
    
    public function get($clear = true)
    {
        $this->add();
        
        foreach ($this->global_opts as $key => $opts)
        {
            $this->global_opts[$key] = $this->encode($opts);
        }    
        
        return $this->process_get($this->global_opts, $clear, 'json');
    }
    
    public function get_array($clear = true)
    {
        $this->add();
        
        return $this->process_get($this->global_opts, $clear, 'array');
    }
    
    public function encode($options)
    {
        $options = str_replace('\\', '', json_encode($options));
        return str_replace($this->replace_keys, $this->orig_keys, $options);
    }
    
    private function process_get($options, $clear, $type)
    {
        if (count($this->shared_opts) > 0)
        {
            $global = ($type == 'json') ? 
            $this->encode($this->shared_opts) : $this->shared_opts;
            
            $options = array('global' => $global, 'local' => $options);
        }
        
        if ($clear === true) $this->clear();
        
        return $options;
    }
    
    public function render()
    {
        $this->add();
        
        $i = 1; $d = 1; $divs = '';

        $embed  = '<script type="text/javascript">'."\n";
        $embed .= '$(function(){'."\n";
        
        foreach ($this->global_opts as $opts)
        {
            if (count($this->shared_opts) > 0 AND $i === 1)
      {
      $embed.='Highcharts.setOptions('.$this->encode($this->shared_opts).');'."\n";
      }

      if ($opts['chart']['renderTo'] == 'hc_chart')
      {
        $opts['chart']['renderTo'] .= '_'.$d;
        $d++;
      }
            
        $embed .= 'var '.$this->js_chart_name.'_'.$i.
                  ' = new Highcharts.Chart('.$this->encode($opts).');'."\n";
            $divs  .= '<div id="'.$opts['chart']['renderTo'].'"></div>'."\n";
            $i++;
        }
        
        $embed .= '});'."\n";
        $embed .= '</script>'."\n";
        $embed .= $divs;
        
        $this->clear();
                
        return $embed;
    }
    
    
    public function clear($shared = false)
    {
        $this->opts = array();
        $this->opts['series'] = array();
        $this->opts['chart']['renderTo'] = 'hc_chart';
        $this->serie_index = 0;
        
        if ($shared === true) $this->shared_opts = array();
        
        return $this;
    }
    
    private function encode_function($array = array())
    {
        if (is_string($array)) {
            $array = $this->delimit_function($array);
        }
        else {
            foreach($array as $key => $value) {
                if (is_array($value)) {
                    $this->encode_function($value);
                }
                else {
                    $array[$key] = $this->delimit_function($value);
                }                
            }
        }
        return $array;
    }
    
    private function delimit_function($string = '')
    {
        if(strpos($string, 'function(') !== false)
        {
          $this->orig_keys[] = $string;
          $string = '$$' . $string . '$$';
              $this->replace_keys[] = '"' . $string . '"';
        }
        return $string;
    }

}

?>

NOTE :

Copy the above code and put to HighCharts_lib.php and put this file in the library folder.




HighCharts Config for CodeIgniter

Below is the code for config file :

HighCharts_config.php :


<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

// shared_options : highcharts global settings, like interface or language
$config['shared_options'] = array(
    'chart' => array(
        'backgroundColor' => array(
            'linearGradient' => array(0, 0, 500, 500),
            'stops' => array(
                array(0, 'rgb(255, 255, 255)'),
                array(1, 'rgb(240, 240, 255)')
            )
        ),
        'shadow' => true
    ),
    'exporting' => array(
        'enabled' =>true,
        'enableImages' => true,
        'buttons' => array(
            'exportButton' => array (
                'enabled' =>true
            )
        )
    ),
        
);

// Template Example
$config['chart_template'] = array(
    'chart' => array(
        'renderTo' => 'graph',
        'defaultSeriesType' => 'column',
        'backgroundColor' => array(
            'linearGradient' => array(0, 500, 0, 0),
            'stops' => array(
                array(0, 'rgb(255, 255, 255)'),
                array(1, 'rgb(190, 200, 255)')
            )
        ),
     ),
     'colors' => array(
          '#ED561B', '#50B432'
     ),
     'credits' => array(
         'enabled'=> true,
         
         'text'    => 'Code 2 Learn',
        'href' => 'www.code2learn.com'
     ),
    'exporting' => array(
        'enabled' =>true,
        'enableImages' => true,
        'buttons' => array(
            'exportButton' => array (
                'enabled' =>true
            )
        )
    ),
     'title' => array(
        'text' => 'Template from config file'
     ),
     'legend' => array(
         'enabled' => false
     ),
    'yAxis' => array(
        'title' => array(
            'text' => 'population'
        )

    ),
    'xAxis' => array(
        'title' => array(
            'text' => 'Countries'
        )
    ),
    'tooltip' => array(
        'shared' => true
    )
);

?>

NOTE :

Copy the code and put it in HighCharts_config.php file and then put that file inside the CONFIG Folder.

We have now defined the two files i.e. library file and config file.

Now lets get started and generate a chart with data taken from mysql db.


Controller


Controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a view port to perform actions based on that input.

Now we write the Controller code which will take data from DB using the Models and will rendering the Charts on webpage using Views.

Application.php :

<?php

class Application extends CI_Controller {

    function Application() {
        parent::__construct();
        $this->load->library('HighCharts_lib.php');
    }


private function index(){
        $data['charts'] = $this->getChart($studentName);
        $this->load->view('charts',$data);
}

private function getChart($stuName) {

        $this->highcharts->set_title('Name of Student :' . $stuName);
        $this->highcharts->set_dimensions(740, 300); 
        $this->highcharts->set_axis_titles('Date', 'Age');
        $credits->href = base_url();
        $credits->text = "Code 2 Learn : HighCharts";
        $this->highcharts->set_credits($credits);
        $this->highcharts->render_to("content_top");

        $result = $this->student_name->getStudentDetails($stuName);

            if ($myrow = mysql_fetch_array($result)) {
                do {
                    $value[] = intval($myrow["age"]);
                    $date[] = ($myrow["date"]);
                } while ($myrow = mysql_fetch_array($result));
            }

            $this->highcharts->push_xcategorie($date);

            $serie['data'] = $value;
            $this->highcharts->export_file("Code 2 Learn Chart".date('d M Y')); 
            $this->highcharts->set_serie($serie, "Age");

            return $this->highcharts->render();

        }
    }

?>

Functions used above are defined in the library, they are :

* set_title($var) : Sets the title of the Chart.
* set_axis_titles($x, $y) : Sets the title of the axis i.e x and y axis resp.
* set_dimension($width, $height)
* set_serie($serie, "Name") : This is the value that you want to be displayed on the chart.
* renderTo : The HTML element where the chart will be rendered. If it is a string, the element by that id is used. The HTML element can also be passed by direct reference. Defaults to null.


Model


Model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.


<?php

class Student_Name extends CI_Model {

    function getStudentDetails($stuName) {
        $query = "PUT YOUR QUERY";
       &nbs