Chart Elements - Menu

The file: js-ofc-library/ofc.js relies on jQuery to function, it requires jQuery.extend() to make a clone of the chart object. If we do not clone the object, removing or updating part of it will lose our original data. I am using jquery-1.2.6.min.js.

The javascript library is very basic at the moment, but there is no reason that it can't be more powerful than the PHP library.

This goes into the <head> of the page:

<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="js-ofc-library/ofc.js"></script>
<script type="text/javascript" src="js/json/json2.js"></script>
<script type="text/javascript" src="js/swfobject.js"></script>

<script type="text/javascript">
swfobject.embedSWF(
"open-flash-chart.swf", "my_chart", "550", "200",
"9.0.0", "expressInstall.swf");


function save_image( chart_id )
{
alert( "Called function: save_image("+ chart_id +")" );
}



function toggle( id )
{
global_showing_old_data = !global_showing_old_data;

var c;
if( global_showing_old_data )
c = global_chart;
else
c = chart_remove_element(global_chart, 0);

tmp = findSWF("my_chart");
x = tmp.load( JSON.stringify(c) );
}

function open_flash_chart_data()
{
return JSON.stringify(global_chart);
}

var global_chart = {"elements":[{"type":"bar_glass","colour":"#BF3B69","text":"Last year","font-size":12,"values":[9,8,7,6,5,4,3,2,1]},{"type":"bar_glass","colour":"#5E0722","text":"This year","font-size":12,"values":[10,9,8,7,6,5,4,3,2]}],"title":{"text":"Thu Jun 20 2013"},"menu":{"colour":"#E0E0ff","outline_colour":"#707070","values":[{"type":"camera-icon","text":"Save image","javascript-function":"save_image"},{"type":"text","text":"Toggle old data","javascript-function":"toggle"}]}}
var global_showing_old_data = true;
</script>
This writes the chart into a div with id="my_chart", right click and view source to see it in action, [the tutorials have more details]

gallery/menu.php
<?php

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

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

$data = array(9,8,7,6,5,4,3,2,1);
$bar = new bar_glass();
$bar->colour'#BF3B69');
$bar->key('Last year'12);
$bar->set_values$data );

$data2 = array(10,9,8,7,6,5,4,3,2);
$bar2 = new bar_glass();
$bar2->colour'#5E0722' );
$bar2->key('This year'12);
$bar2->set_values$data2 );

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

$m = new ofc_menu("#E0E0ff""#707070");
$m->values(array(new ofc_menu_item_camera('Hello','save_image'), new ofc_menu_item_camera('Toggle old data','toggle')));
$chart->set_menu($m);

echo 
$chart->toString();
To see the data produced : gallery/menu.php, then 'view source'.
Support This Project
Adverts:


Open Flash Chart logo by numb.me.uk. | Syntax highlights are by GeSHi