Open Flash Chart
Support This Project :: Home - Gallery - Bar Chart Links
Info: Open Flash Chart 2 is out. Version 1.x and these pages will never disappear and the charts will continue working forever, but further development on 1.x has stopped. Take a look at version 2 here Open Flash Chart 2.

Gallery - Bar Chart Links

Add links to the graph.

Method: add()

$bar->add_link( integer $data, string $link )
I guess you have used the:
$bar->data[] = 10;
$bar->data[] = 20;
style of adding data to your bar charts. The add() method allows you to add a bar and a URL link for that bar. In this example we are using a javascript link, but you can also use normal "" style links. So replacing the two lines above with:
$bar->add( 10, "javascript:alert('Hello World')" );
$bar->add( 20, "" );
will create the same bar chart, but when you click on the first bar, a javascript pop-up will show 'Hello World'. Clicking on the second bar will cause the browser to navigate to that URL.

There is a know bug, grouped bar charts (like these) do not always recieve the click event properly. So please don't use these with links until I fix the bug.

Create the flash object
include_once 'ofc-library/open_flash_chart_object.php';
open_flash_chart_object500300'http://'$_SERVER['SERVER_NAME'] .'/open-flash-chart/gallery-data-46.php' );

include_once( 'ofc-library/open-flash-chart.php' );

// generate some random data

$bar = new bar50'#0066CC' );
$bar->key'Kittens'10 );

$i=0$i<9$i++ )
// add a bar (of randome height) and a URL link
$bar->add_linkrand(2,9), "javascript:alert('Kittens: Bar $i')" );

$g = new graph();
$g->title'Bar Chart''{font-size: 26px;}' );

$g->data_sets[] = $bar;

$g->set_x_labels( array( 'January','February','March','April','May','June','July','August','September' ) );
// set the X axis to show every 2nd label:
// and tick every second value:

$g->set_y_max10 );
$g->set_y_legend'Open Flash Chart'12'0x736AFF' );
To see the data produced : gallery-data-46.php, then 'view source'.
Help support the project: Support This Project