Welcome Guest, Not a member yet? Register   Sign In
pChart 2.0 with Codeigniter
#1

In my project I was need PChart 2.0 and I start searching fast way how to integrate this libraries, and no complite solution was founded, so I start to integrate it by myself, and I like to share my practices with community. I want to notice thats I am using 2.2.1 CI, do not know if its work for CI 3.0.0

First at all download pChart and unpack it to  "application/third_party/chart" folder (you can delete example folder btw)
Then create new folder "libraries" in "application/third_party/chart". Inside this new folder create file pchart.php with next content

PHP Code:
<?php

class Pchart
{
 
   public function __construct() // or any other method
 
   {
 
       require_once APPPATH.'third_party/chart/class/pData.class.php';
 
       require_once APPPATH.'third_party/chart/class/pDraw.class.php';
 
       require_once APPPATH.'third_party/chart/class/pImage.class.php';
 
   }
 
   function pData(){
 
       return new pData();    
    
}
 
   function pImage($n,$i,$data=NULL,$trans=FALSE){
 
       return new pImage($n,$i,$data,$trans);
 
   }


Now, I can create my controller function with example from pChart page:

PHP Code:
  function chart(){
 
       $this->load->add_package_path(APPPATH.'third_party/chart/');
 
       $this->load->library('pchart');  


        
/* Add data in your dataset */ 
 
       $PDA $this->pchart->pData();
 
       $PDA->addPoints(array(VOID,3,4,3,5));  
        
/* Create a pChart object and associate your dataset */ 
 
       $PDI $this->pchart->pImage(700,230,$PDA); 
 
       /* Choose a nice font */
 
       $PDI->setFontProperties(array("FontName"=>APPPATH.'third_party/chart/fonts/Forgotte.ttf',"FontSize"=>11));

 
       /* Define the boundaries of the graph area */
 
       $PDI->setGraphArea(60,40,670,190);

 
       /* Draw the scale, keep everything automatic */ 
 
       $PDI->drawScale();

 
       /* Draw the scale, keep everything automatic */ 
 
       $PDI->drawSplineChart();

 
       /* Build the PNG file and send it to the web browser */ 
 
       $PDI->Render("basic.png");

 
   

And in the end I got my render. Hope its help to you as well.
Reply
#2

Nice, thanks for sharing.
Reply
#3

thanks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB