PHP之Flash数据图表类库
时间:2008-01-11 来源:panzt
Open Flash Chart是一个开源的Flash图表显示类库,支持.Net,Java,PHP,Perl,Ruby等动态语言来构建动态的Flash数据图表。
相关链接:http://teethgrinder.co.uk/open-flash-chart/gallery-inner-bg.php
OK,闲话少叙,看一个饼图的示例代码:
1、Chart.php
<?php
include_once 'php-ofc-library/open_flash_chart_object.php';
open_flash_chart_object( 200, 150, 'http://'. $_SERVER['SERVER_NAME'] .'/chart/chart-data.php', false );
?>
2、数据文件 chart-data.php
<?php
// generate some random data:
srand((double)microtime()*1000000);
$max = 50;
$data = array();
for( $i=0; $i<12; $i++ ){
$data[] = rand(0,$max);
}
// use the chart class to build the chart:
include_once( 'php-ofc-library/open-flash-chart.php' );
$g = new graph();
// Spoon sales, March 2007
$g->title( 'Spoon sales '. date("Y"), '{font-size: 26px;}' );
$g->set_data( $data );
// label each point with its value
$g->set_x_labels( array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec' ) );
// set the Y max
$g->set_y_max( 60 );
// label every 20 (0,20,40,60)
$g->y_label_steps( 6 );
// display the dataecho
$g->render();
?>
3.不要忘记将open-flash-chart.swf拷贝至根目录下
现在看来,基于数组的PHP有其自身强大的优势,也是其经久不衰的原因所在吧。
基于数组,换个想法,就是基于XML,再换个想法,就是基于简约格式的数据,正是这种简约带动了XML的流行,也推动了PHP的老树新春,所以简约就是时尚不是一句空话,是切切实实的真理。
闲话说完,看看另外两款基于XML作为数据源的Flash Chart
1、PHP/SWF Charts
相关链接:http://www.maani.us/charts/index.php
简单示例:chart.php
<HTML>
<BODY bgcolor="#FFFFFF">
<?php
//include charts.php to access the InsertChart function
include "charts.php";
echo InsertChart ( "charts.swf", "charts_library", "sample.php", 400, 250 );
?>
</BODY>
</HTML>
sample.php
<?php
//include charts.php to access the SendChartData function
include_once("charts.php");
SendChartData ();
?>
2.FusionCharts
相关链接:http://www.fusioncharts.com/free/Default.asp
Data.xml
<chart caption='Monthly Sales Summary' subcaption='For the year 2006' xAxisName='Month' yAxisName='Sales' numberPrefix='$'>
<set label='January' value='17400' />
<set label='February' value='19800' />
<set label='March' value='21800' />
<set label='April' value='23800' />
<set label='May' value='29600' />
<set label='June' value='27600' />
<set label='July' value='31800' />
<set label='August' value='39700' />
<set label='September' value='37800' />
<set label='October' value='21900' />
<set label='November' value='32900' />
<set label='December' value='39800' />
</chart>
Chart.html
<html>
<head>
<title>My First FusionCharts</title>
</head>
<body bgcolor="#ffffff">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="900" height="300" id="Column3D" >
<param name="movie" value="Charts/Column3D.swf" />
<param name="FlashVars" value="&dataURL=Data.xml">
<param name="quality" value="high" />
<embed src="../FusionCharts/Column3D.swf" flashVars="&dataURL=Data.xml" quality="high" width="900" height="300" name="Column3D" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>
各位还在等什么呢,赶快去体验一下Flash图表带来的震撼效果吧!
相关链接:http://teethgrinder.co.uk/open-flash-chart/gallery-inner-bg.php
OK,闲话少叙,看一个饼图的示例代码:
1、Chart.php
<?php
include_once 'php-ofc-library/open_flash_chart_object.php';
open_flash_chart_object( 200, 150, 'http://'. $_SERVER['SERVER_NAME'] .'/chart/chart-data.php', false );
?>
2、数据文件 chart-data.php
<?php
// generate some random data:
srand((double)microtime()*1000000);
$max = 50;
$data = array();
for( $i=0; $i<12; $i++ ){
$data[] = rand(0,$max);
}
// use the chart class to build the chart:
include_once( 'php-ofc-library/open-flash-chart.php' );
$g = new graph();
// Spoon sales, March 2007
$g->title( 'Spoon sales '. date("Y"), '{font-size: 26px;}' );
$g->set_data( $data );
// label each point with its value
$g->set_x_labels( array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec' ) );
// set the Y max
$g->set_y_max( 60 );
// label every 20 (0,20,40,60)
$g->y_label_steps( 6 );
// display the dataecho
$g->render();
?>
3.不要忘记将open-flash-chart.swf拷贝至根目录下
现在看来,基于数组的PHP有其自身强大的优势,也是其经久不衰的原因所在吧。
基于数组,换个想法,就是基于XML,再换个想法,就是基于简约格式的数据,正是这种简约带动了XML的流行,也推动了PHP的老树新春,所以简约就是时尚不是一句空话,是切切实实的真理。
闲话说完,看看另外两款基于XML作为数据源的Flash Chart
1、PHP/SWF Charts
相关链接:http://www.maani.us/charts/index.php
简单示例:chart.php
<HTML>
<BODY bgcolor="#FFFFFF">
<?php
//include charts.php to access the InsertChart function
include "charts.php";
echo InsertChart ( "charts.swf", "charts_library", "sample.php", 400, 250 );
?>
</BODY>
</HTML>
sample.php
<?php
//include charts.php to access the SendChartData function
include_once("charts.php");
SendChartData ();
?>
2.FusionCharts
相关链接:http://www.fusioncharts.com/free/Default.asp
Data.xml
<chart caption='Monthly Sales Summary' subcaption='For the year 2006' xAxisName='Month' yAxisName='Sales' numberPrefix='$'>
<set label='January' value='17400' />
<set label='February' value='19800' />
<set label='March' value='21800' />
<set label='April' value='23800' />
<set label='May' value='29600' />
<set label='June' value='27600' />
<set label='July' value='31800' />
<set label='August' value='39700' />
<set label='September' value='37800' />
<set label='October' value='21900' />
<set label='November' value='32900' />
<set label='December' value='39800' />
</chart>
Chart.html
<html>
<head>
<title>My First FusionCharts</title>
</head>
<body bgcolor="#ffffff">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="900" height="300" id="Column3D" >
<param name="movie" value="Charts/Column3D.swf" />
<param name="FlashVars" value="&dataURL=Data.xml">
<param name="quality" value="high" />
<embed src="../FusionCharts/Column3D.swf" flashVars="&dataURL=Data.xml" quality="high" width="900" height="300" name="Column3D" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>
各位还在等什么呢,赶快去体验一下Flash图表带来的震撼效果吧!
相关阅读 更多 +