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

[eluser]pickupman[/eluser]
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
Code:
$this->load->helper('open-flash-chart');

Call the function open_flash_chart_object_str
Code:
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
Code:
$data['content'] = open_flash_chart_object_str('700','350',site_url('charts/item_track'),false,base_url());

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

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

<code>
$data['url'] = "charts/item_track";
$data['width'] = 700;
$data['height'] = 350;
$data['useswfobject'] = false;

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

then view:

<code>
<h1>Heading...</h1>
&lt;?=open_flash_chart_object_str($width, $height, site_url($url), $useswfobject, base_url())?&gt;
<p>If you are having problems viewing the chart above, please get the latest <a href="http://adobe.com/go/getflashplayer" rel="nofollow">Adobe Flash Player</a>.</p>
</code>

There's probably something wrong with that code, but you get the idea...

Isaac
#13

[eluser]oste15[/eluser]
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.
#14

[eluser]iamjerson[/eluser]
i am also having problem w/ integrating OFC to CI can anyone post a tutorial on how we use Mesozoic Library..
#15

[eluser]getSurreal[/eluser]
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?
#16

[eluser]pickupman[/eluser]
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.
#17

[eluser]ch5i[/eluser]
EDIT:

This is old information

See this post for an update.

I'll leave the contents of this post, as it is still valid (but a rather complicated approach).

br,
Thomas

***

OLD

I created a small library that allows to use Open Flash Chart 2 in CodeIgniter.

This is the old file.


Library
Code:
&lt;?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* Provides a factory for Open Flash Chart2 objects
*
* @package CodeIgniter
* @subpackage Open Flash Chart 2
* @category Library
* @author thomas(at)kbox.ch
*/
class Ofc2Factory
{
    /**
     * Constructor
     *
     * Loads OFC2 class definition files. Need to change working directory
     * temporarily, so that the links within the original class files work
     * for loading
     */
    public function __construct()
    {
        $old_cwd = getcwd();
        chdir(dirname(__FILE__)); //change cwd to the dir of this file
        require_once('OFC/OFC_Chart.php');
        chdir($old_cwd);
    }

    /**
     * Creates OFC2 objects from a passed classname and optional
     * array of arguments
     *
     * @param string $classname
     * @param array $arguments
     * @return mixed
     */
    public function create($classname, $arguments = array())
    {
        // check if class is defined
        if (class_exists($classname))
        {
            return call_user_func_array(
                    array(new ReflectionClass($classname), 'newInstance'),
                    $arguments
                   );
        }
        else
        {
            die("Sorry can't create the object, class [$classname] not defined");
        }
    }
}

It works as an object factory for OFC2 objects.
The library expects to find the open flash chart classes folder 'OFC' inside the libraries folder.

Usage:

Controller
Code:
&lt;?php

/**
* OFC2 Chart Controller
*
* @package CodeIgniter
* @author thomas(at)kbox.ch
*/
class Ofc2_chart extends Controller {

    /**
     * Constructor
     */
    function __construct()
    {
        parent::__construct();
    }

    /**
     * Gets called automatically if no controller function given
     */
    public function index()
    {
        $this->run_test();
    }

    /**
     * Loads the OFC2 test view
     */
    public function run_test()
    {
        $data = array(
                    'data_url' => $this->config->item('base_url').'ofc2_chart/get_data',
                    'page_title' => 'OFC2 Test'
                );

        $this->load->view('ofc2_chart_view', $data);
    }

    /**
     * Generates data for OFC2 in json format (example)
     */
    public function get_data()
    {
        // load the factory and give it a shorthand alias
        $this->load->library('Ofc2factory', NULL, 'ofc2');

        // start creating objects
        $title = $this->ofc2->create('OFC_Elements_Title', array("Our new House Schedule"));

        $hbar = $this->ofc2->create('OFC_Charts_Bar_Horizontal');
        $hbar->append_value($this->ofc2->create('OFC_Charts_Bar_Horizontal_Value', array(0,4)));
        $hbar->append_value($this->ofc2->create('OFC_Charts_Bar_Horizontal_Value', array(4,8)));
        $hbar->append_value($this->ofc2->create('OFC_Charts_Bar_Horizontal_Value', array(8,11)));

        $chart = $this->ofc2->create('OFC_Chart');
        $chart->set_title($title);
        $chart->add_element($hbar);
        $chart->add_y_axis($this->ofc2->create('OFC_Elements_Axis_Y'));

        $x = $this->ofc2->create('OFC_Elements_Axis_X');
        $x->set_offset(false);
        $x->set_labels_from_array(array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'));
        $chart->set_x_axis($x);

        $y = $this->ofc2->create('OFC_Elements_Axis_Y');
        $y->set_offset(true);
        $y->set_labels(array("Make garden look sexy","Paint house","Move into house"));
        $chart->add_y_axis($y);

        // send response (json)
        echo $chart->toString();
    }

}


View (mangled by forum SW, see linked file in Wiki)
Code:
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;&lt;?= $page_title ?&gt;&lt;/title&gt;
        &lt;base href="&lt;?= $this-&gt;config->item('base_url') ?&gt;" />
        [removed][removed]
    &lt;/head&gt;

    &lt;body&gt;

        <h1>&lt;?= $page_title ?&gt;</h1>
        [removed]
            swfobject.embedSWF(
              "assets/swf/open-flash-chart.swf", "test_chart", "950", "150",
              "9.0.0", "expressInstall.swf",
              {"data-file":"&lt;?= urlencode($data_url) ?&gt;"}
              );
        [removed]

        <div id="test_chart"></div>

    &lt;/body&gt;
&lt;/html&gt;

br,
Thomas
#18

[eluser]umefarooq[/eluser]
really nice library and working fine with my poll module i really love this library and work done by @Mesozoic and @pickupman great job.
#19

[eluser]Unknown[/eluser]
Hello everybody,

I'm trying to implement this in my website. But i have trouble using the library. Does somebody have some examples for me how to make a line graph?

The example above works, but how do i change the values for a line chart. I tried this:

Code:
public function get_start_data()
    {
        $data_1 = array();
        $data_2 = array();
        $data_3 = array();
        
        for( $i=0; $i<6.2; $i+=0.2 )
        {
          $data_1[] = (sin($i) * 1.9) + 10;
          $data_2[] = (sin($i) * 1.9) + 7;
          $data_3[] = (sin($i) * 1.9) + 4;
        }
        // load the factory and give it a shorthand alias
        $this->load->library('Ofc2factory', NULL, 'ofc2');

        // start creating objects
        $title = $this->ofc2->create('OFC_Elements_Title', array("Test"));

        $line_l = $this->ofc2->create('OFC_Charts_Line');
        $line_1->set_values($data_1);
      
        $chart = $this->ofc2->create('OFC_Chart');
        $chart->set_title($title);
        $chart->add_element($line_1);
        $chart->add_y_axis($this->ofc2->create('OFC_Elements_Axis_Y'));

        $x = $this->ofc2->create('OFC_Elements_Axis_X');
        $x->set_offset(false);
        $x->set_labels_from_array(array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'));
        $chart->set_x_axis($x);

        $y = $this->ofc2->create('OFC_Elements_Axis_Y');
        $y->set_offset(true);
        //$y->set_labels(array("Make garden look sexy","Paint house","Move into house"));
        $chart->add_y_axis($y);

        // send response (json)
        echo $chart->toString();
    }

But that gives a error.

Hope that you can help!
#20

[eluser]naim[/eluser]
For me too.
If it should work out from the box - it isn'tWink




Theme © iAndrew 2016 - Forum software by © MyBB