Welcome Guest, Not a member yet? Register   Sign In
OpenFlashChart 2 and Codeigniter
#1

[eluser]Unknown[/eluser]
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:

Code:
<?
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;
?&gt;

<|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(movieName) { if (navigator.appName.indexOf("Microsoft")!= -1) { return window[movieName]; } else { return document[movieName]; } }
var data_1 = &lt;?php echo $chart1->toPrettyString(); ?&gt;;
<|/script>

Here:
Code:
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:
Code:
<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.
#2

[eluser]Mesozoic[/eluser]
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.
#3

[eluser]Unknown[/eluser]
Hehe Smile What a simple solution. Can you and a zip file with an example please.
#4

[eluser]Mesozoic[/eluser]
Here you go. I added functions that create new charts so whenever the examples use like

Code:
new pie()

just call
Code:
$this->ofc->pie()
instead.

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

[eluser]pickupman[/eluser]
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.
Code:
include '../php-ofc-library/open-flash-chart.php';

$title = new title( date("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:
Code:
$this->load->library('ofc');

$title = $this->ofc->title( date("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();
#6

[eluser]Unknown[/eluser]
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 :-)
#7

[eluser]Unknown[/eluser]
very helpful for interview..thank you so much
#8

[eluser]dinhtrung[/eluser]
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:
Quote:&lt;?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<br>#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...
Quote:&lt;html&gt;
&lt;head&gt;
&lt;?php
if (is_array($javascript)){
foreach ($javascript as $j)
echo "[removed][removed]"
}
if (isset($jsscript))
echo "[removed]\n".$jsscript."[removed]\n";
?&gt;
&lt;/head&gt;
&lt;body&gt;
<div class='wrap'>
&lt;?= $main; ?&gt;
</div>
&lt;/body&gt;
&lt;/html&gt;
#9

[eluser]IsaacS[/eluser]
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
#10

[eluser]Unknown[/eluser]
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?




Theme © iAndrew 2016 - Forum software by © MyBB