Part of the EllisLab Network
   
1 of 2
1
OpenFlashChart 2 and Codeigniter
Posted: 21 June 2009 06:35 PM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  3
Joined  06-05-2008

When OpenFlashChart 2 came out, all the CI stuff, using a plugin and creating the charts from CI went down the toilet because the author did the smart thing and created classes in different files.

I searched the net for a solution and didn’t found one. So my question is:

Has anyone made a plugin for OpenFlashChart v2 for Codeigniter?

If not to solve your problem quickly all you need to do is use your view file to render the chart. So in your view file just write:

<?
include ('OFC/php-ofc-library/open-flash-chart.php');
//Defaults
$toolTip '#val# of #total#<br>#percent# of 100%';

$title1 = new title"Top Artisti" );
$pie1 = new pie();
$pie1->set_alpha(0.6);
$pie1->add_animation( new pie_bounce(8) );
$pie1->add_animation( new pie_fade() );
$pie1->set_tooltip$toolTip );
$pie1->set_colours( array('#D544A2','#9408E0','#E25374') );

foreach(
$DB_FROM_CONTROLER->result() as $row)
{$pieArr1[] = new pie_value(intval($row->DBROW1), $row->DBROW2);}

$pie1
->set_values$pieArr1 );//Pie 1

//Pie 1
$chart1 = new open_flash_chart();
$chart1->set_bg_colour('#EEEEEE');
$chart1->set_title$title1 );
$chart1->add_element$pie1 );
$chart1->x_axis null;
?>

<|script type="text/javascript" src="OFC/js/json/json2.js"><|/script>
<|
script type="text/javascript" src="OFC/js/swfobject.js"><|/script>
<|
script type="text/javascript">
swfobject.embedSWF("OFC/open-flash-chart.swf""my_chart_1""400""300""9.0.0""expressInstall.swf"{"get-data":"get_data_1"});
function 
ofc_ready() {/*alert('ofc_ready');*/}
function get_data_1(){return JSON.stringify(data_1);}
function findSWF(movieNameif (navigator.appName.indexOf("Microsoft")!= -1return window[movieName]else return document[movieName]} }
var data_1 <?php echo $chart1->toPrettyString(); ?>;
<|/
script

Here:

foreach($DB_FROM_CONTROLER->result() as $row)
{$pieArr1[] = new pie_value(intval($row->DBROW1), $row->DBROW2);

I’m just converting the query data to the my PIE chart array.

Now all you need to do is to insert a div tag where the chart should be showed:

<div id="my_chart_1"></div

And this is it, works like a charm. I know is the most stupid way and wrong way to implement this but until I figure out how to make the chart lib as a plugin perhaps this will be helpful.

If you need help with the formating just consult the manual for the chart lib.

NOTE: <|/script> remove the | sign , I have add it to show correctly.

Profile
 
 
Posted: 25 June 2009 12:45 AM   [ Ignore ]   [ # 1 ]  
Summer Student
Avatar
Total Posts:  2
Joined  06-25-2009

Well I just merged all the class files into one file, renamed it as directed by code igniter user guide. Then loaded it as a library and with just a bit of tinkering it worked fine.

Profile
 
 
Posted: 25 June 2009 03:37 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Avatar
Total Posts:  3
Joined  06-05-2008

Hehe smile What a simple solution. Can you and a zip file with an example please.

Profile
 
 
Posted: 25 June 2009 12:36 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Avatar
Total Posts:  2
Joined  06-25-2009

Here you go. I added functions that create new charts so whenever the examples use like

new pie() 

just call

$this->ofc->pie() 

instead.

I only did pie and bar I think but its pretty easy to see how to expand.

File Attachments
Ofc.zip  (File Size: 8KB - Downloads: 431)
Profile
 
 
Posted: 05 July 2009 07:47 PM   [ Ignore ]   [ # 4 ]  
Lab Technician
RankRankRankRank
Total Posts:  1159
Joined  03-30-2009

Thanks for the upload. Took a minute to wrap my mind around what you did. I then looked if there would be a neater solution using CI naming in librariers, but it seemed to be making the code bigger not better. There are too many different objects in OFC to simplify this.
ie.(
$this->ofc->intialize($config);
$this->ofc->add_element($data);
$this->ofc->generate();
)
Here is an example taken from the open flash chart site for the line chart. Seems easy enough.

include '../php-ofc-library/open-flash-chart.php';

$title = new titledate("D M d Y") );

$line_dot = new line();
$line_dot->set_values( array(1,2,1,null,null,null,null,null) );

$chart = new open_flash_chart();
$chart->set_title$title );
$chart->add_element$line_dot );

echo 
$chart->toPrettyString(); 

Now you would use:

$this->load->library('ofc');

$title $this->ofc->titledate("D M d Y") );
$line $this->ofc->line();
$line->set_values( array(1,2,1,null,null,null,null,null) );
        
$this->ofc->open_flash_chart();
$this->ofc->set_title$title );
$this->ofc->add_element$line );
        
echo 
$this->ofc->toPrettyString(); 
 Signature 

Useful CI Links
Base Controllers by Phil Sturgeon
Cache Library by Phil Sturgeon
Carabiner css/js management by tonydewan

Profile
 
 
Posted: 24 July 2009 06:21 AM   [ Ignore ]   [ # 5 ]  
Summer Student
Avatar
Total Posts:  1
Joined  07-24-2009

Dear All, mesozoic and pickupman.
I do this technique to my Apps, and it works, thx!

For the reader:
after you attach the mesozoic ofc library,
by default it just only work for bar and pie only.
You must open the Ofc.php and add some new function on class Ofc for improvement.

Expecto patronum grin

Profile
 
 
Posted: 24 July 2009 06:43 AM   [ Ignore ]   [ # 6 ]  
Summer Student
Total Posts:  1
Joined  07-24-2009

very helpful for interview..thank you so much

Profile
 
 
Posted: 31 July 2009 01:49 PM   [ Ignore ]   [ # 7 ]  
Grad Student
Avatar
Rank
Total Posts:  74
Joined  11-16-2008

Okay, I’ve got it. No need for merge all the included libraries in php-ofc-library/open-flash-chart.php. Instead, you can use it purely from your controller. For an example:

<?php
if (!defined(‘BASEPATH’)) exit(‘No direct script access allowed’);
class Devel extends Controller {
  var $site = array();
 
  function __construct() {
      parent::Controller();         
  }
 
  function index() {
      $this->site[‘javascript’] = array(‘swfobject.js’);
      $this->site[‘jsscript’] = ‘swfobject.embedSWF(”’.base_url().‘assets/swf/open-flash-chart.swf”, “my_chart”,“550”, “200”, “9.0.0”, “expressInstall.swf”,{“data-file”:”’.base_url().‘devel/data”} );’;
      $this->site[‘main’] = ‘<div id=“my_chart”></div>’;
      $this->load->view(‘main_template’, $this->site); 
  }
 
  function data(){
        require_once(APPPATH.‘assets/ofc/open-flash-chart.php’);
       
        $title = new title( date(“D M d Y”) );
       
        $data = array(9,8,7,6,null,4,3,2,1);
        $data[4] = new bar_value(5);
        $data[4]->set_colour( ‘#ff0000’ );
        $data[4]->set_tooltip( ‘Hello
#val#’ );
       
        $bar = new bar_glass();
        $bar->set_values( $data );
       
        $chart = new open_flash_chart();
        $chart->set_title( $title );
        $chart->add_element( $bar );
       
        echo $chart->toString();
  }
}
/* End of file : system/application/controllers/uploadtest.php */

And for the view, something like this…

<html>
<head>
<?php
if (is_array($javascript)){
  foreach ($javascript as $j)
      echo “[removed][removed]”
}
if (isset($jsscript))
  echo “[removed]\n”.$jsscript.”[removed]\n”;
?>
</head>
<body>
  <div class=‘wrap’>
      <?= $main; ?>
  </div>
</body>
</html>

Profile
 
 
Posted: 09 August 2009 06:30 AM   [ Ignore ]   [ # 8 ]  
Summer Student
Total Posts:  15
Joined  07-23-2009

Mesozoic’s solution is absolutely fantastic! Works perfectly, and the controller code looks like it’s one of the built-in libraries.

Thank you!

Isaac

Profile
 
 
Posted: 11 August 2009 08:18 AM   [ Ignore ]   [ # 9 ]  
Summer Student
Total Posts:  1
Joined  08-11-2009

I still can’t get this to work. I have my controller function complete so it echo the toPrettyString(), but how do I hook this up with a view, all I am seeing in my view is the string. Do I need to install anything else?

Profile
 
 
Posted: 18 August 2009 09:13 AM   [ Ignore ]   [ # 10 ]  
Lab Technician
RankRankRankRank
Total Posts:  1159
Joined  03-30-2009

Now you need to call the outputted json string from your page. I have my json strings generated by /applications/controllers/charts.php.
One of my functions is item_track. So if I call http://website.com/charts/item_track I get my outputted json string.
Then I can generate reports from a controller called reports. You will need to load the open-flash-chart_helper.php by using

$this->load->helper('open-flash-chart'); 

Call the function open_flash_chart_object_str

open_flash_chart_object_str$width$height$url$use_swfobject=true$base='' )

//$width of graph (ie. '700')
//$height of graph (ie. '350')
//$url to json string (ie site_url('charts/item_track') )
//$use_swfobject (ie true/false) I have swfobject already loaded so I have it set to false
//$base (ie base_url() ) 

Here’s how mine looks

$data['content'open_flash_chart_object_str('700','350',site_url('charts/item_track'),false,base_url());

$this->load->view('reports/view',$data); 
 Signature 

Useful CI Links
Base Controllers by Phil Sturgeon
Cache Library by Phil Sturgeon
Carabiner css/js management by tonydewan

Profile
 
 
Posted: 18 August 2009 03:08 PM   [ Ignore ]   [ # 11 ]  
Summer Student
Total Posts:  15
Joined  07-23-2009

Surely it would be more MVC to have all the content-generation done in the view? So controller:


$data[‘url’] = “charts/item_track”;
$data[‘width’] = 700;
$data[‘height’] = 350;
$data[‘useswfobject’] = false;

$this->load->view(‘reports/view’, $data);

then view:


<h1>Heading…</h1>
<?=open_flash_chart_object_str($width, $height, site_url($url), $useswfobject, base_url())?>
If you are having problems viewing the chart above, please get the latest Adobe Flash Player.

There’s probably something wrong with that code, but you get the idea…

Isaac

Profile
 
 
Posted: 17 September 2009 08:36 AM   [ Ignore ]   [ # 12 ]  
Summer Student
Total Posts:  8
Joined  09-17-2009

Do I need a helper file? or am I missing something here?

This seems like a complex thing to setup, if someone is willing to post a well documented tutorial I think that would be great, and I am sure it will help out many others down the road. Just a thought.

Thanks.

Profile
 
 
Posted: 07 October 2009 05:33 PM   [ Ignore ]   [ # 13 ]  
Summer Student
Total Posts:  17
Joined  02-11-2009

i am also having problem w/ integrating OFC to CI can anyone post a tutorial on how we use Mesozoic Library..

 Signature 

http://www.findphilippineseminars.com (CI)
http://www.sportspickcenter.com (CI)
http://www.myweblancers.com/ (Wordpress)
http://www.botechnology.com/ (Joomla)

Profile
 
 
Posted: 21 October 2009 11:24 PM   [ Ignore ]   [ # 14 ]  
Summer Student
Total Posts:  17
Joined  09-18-2009

I’ve got Mesozoic’s ofc class working. I was able to add a couple extra features that he left off like tags and line charts, but I’m unable to make the lines with dots, or hollow dots work.  Has anyone else extended this to encompass all the classes that OFC has?

Profile
 
 
Posted: 22 October 2009 08:52 AM   [ Ignore ]   [ # 15 ]  
Lab Technician
RankRankRankRank
Total Posts:  1159
Joined  03-30-2009

I started to extend this class to use CI’s syntax, but after doing 10 classes I realized this was just redundant. It seems just best to use the class as is. It’s way too big to rewrite to incorporate all of the features of each graph.

 Signature 

Useful CI Links
Base Controllers by Phil Sturgeon
Cache Library by Phil Sturgeon
Carabiner css/js management by tonydewan

Profile
 
 
   
1 of 2
1
 
‹‹ uri problem      mkdir problems ››