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

[eluser]ch5i[/eluser]
Hello,

sorry for the late reply, have been very busy lately...


I have changed the OFC2 library to a simple plugin.

See the updated wiki article Open Flash Chart 2 Plugin

This is much easier, and now really should work as advertised Wink

Here's the new package: download

Instructions
1) Drop the contents of the ‘application’ folder into your application folder
2) Drop the ‘assets’ folder into your webroot (next to your index.php file)
3) Open your.hostname.com/index.php/ofc2


br,
Thomas
#22

[eluser]carvingCode[/eluser]
Just now beginning to delve into the OFC2 plugin examples.

I need to display a OFC2 charts within an existing view. The view contains usage statistics and the chart will be another representation of the stats.

Any ideas on how to do this?

TIA
#23

[eluser]pickupman[/eluser]
[quote author="carvingCode" date="1273080298"]Just now beginning to delve into the OFC2 plugin examples.

I need to display a OFC2 charts within an existing view. The view contains usage statistics and the chart will be another representation of the stats.

Any ideas on how to do this?

TIA[/quote]
You need to create a method that will parse your statistics into JSON for the format of chart you need. Refer to OFC's documentation for that. Then you will call OFC's chart point the data url to your JSON method.
#24

[eluser]carvingCode[/eluser]
What I've done so far:

1) Copied the 'get_bar_data()' function into my controller. (Using default function and dataset for test).
2) Added the Javascript found in the example view file into my view. Made necessary updates to align the Flash file to a DIV on my page and hard coded in the URL to the controller function.

I can get the flash file inserted into the location in my view. But, it doesn't import the data. It's basically an empty Flash file.

I can run the controller/function and it returns the default dataset:

Code:
{ "elements": [ { "type": "bar", "values": [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] } ], "title": "test" }

I'm getting no CI and Javascript errors. But I have, intermittently, received a JSON error.

Things seem to be connecting up OK, but not getting the results.

Any ideas?
#25

[eluser]pickupman[/eluser]
Can you post your view file showing how you are loading the chart?
#26

[eluser]carvingCode[/eluser]
Here it is.

Code:
<?php
    $this->load->view('parts/head');
    $output = "<div id=\"sub-heading\">\n";
    $output .= "<h2>Admin Menu</h2>\n";
    $output .= "</div>\n";
    $output .= "<div id=\"content\">\n";
    $output .= "<div id=\"stats\">\n";
    $output .= "<div id=\"stats-left\">\n";
    $output .= "<h3>Totals</h3>\n";
    $output .= "<table>\n";
    $line_num=0;
    foreach ($query->result_array() as $record)
    {
        if ($line_num++ % 2) {
            $output .= "<tr class=\"odd\">";
        }
        else
        {
            $output .= "<tr class=\"even\">";
        }
        $output .= "<td class=\"cat-name\">".ucwords($record['category'])."</td>";
        $output .= "<td class=\"cat-totals\">".$record['cat_totals']."</td>";
        $output .= "</tr>\n";
    }

    $output .= "</table>\n";
    $output .= "</div>\n";
    $output .= "<div id=\"stats-right\">\n";
    echo $output;
    ?&gt;

[removed]
[removed]
[removed]
            swfobject.embedSWF(
              "http://server/assets/swf/open-flash-chart.swf", "stats-right",
              "260", "490",
              "9.0.0", "expressInstall.swf",
              {"data-file":"&lt;?= urlencode('http://server/controller/get_data_bar') ?&gt;"}
             );
[removed]

    &lt;?php
    $output = "</div>\n";
    $output .= "</div>\n";

    echo $output;

    //Load page footer
    $this->load->view('parts/foot');

    /* End of file admin.php */
    /* Location: ./system/application/views/admin */

Not sure why EE removed the script tags... That's what is behind the '[removed]' lines. I'm placing the Javascript call to the 'swfobject.js' in the DIV that I need it to display to.

What I now getting is the 'loading' graphics for the Flash file. It's just not getting the data...
#27

[eluser]pickupman[/eluser]
It looks like your view is correct, and if OFC is trying to load the data, it seems you've got that part right. Take a look at all of your json. Make sure have defined each of the required elements (ie x-axis, y-axis, color). You might try copying the json from the tutorials on the OFC website, and have your controller output that string. That could help narrow down where the problem is.
#28

[eluser]carvingCode[/eluser]
[quote author="pickupman" date="1273091361"]It looks like your view is correct, and if OFC is trying to load the data, it seems you've got that part right. Take a look at all of your json. Make sure have defined each of the required elements (ie x-axis, y-axis, color). You might try copying the json from the tutorials on the OFC website, and have your controller output that string. That could help narrow down where the problem is.[/quote]

Will do. Right now, I'm relying only on the 'get_data_bar()' function of the CI plugin to generate the data in the proper format. And I've not made any changes to it. I assumed that as it was working in the demos, it should be all that was needed for testing.
#29

[eluser]carvingCode[/eluser]
OK. Copying the dataset from the bar example gets things working. Will work on this more after lunch and report back. But, looks like success is looming.

Thanks for the suggestion.

EDIT: OK... My fault. I forgot that I had made a change to the get_data_bar() function. This caused the format of the dataset to be wrong. Fixed, and all is well with the test data. Now on to the real deal.

Again, thanks for the suggestion to compare datasets. That was the solver.
#30

[eluser]carvingCode[/eluser]
OFC2 is running fine on my hosted server but just displays the 'loading' message and rotating thingy on my localhost install. The sites are exact duplicates.

Do I need to make a path change or make sure a specific PHP library is running?

TIA




Theme © iAndrew 2016 - Forum software by © MyBB