$sql = "SELECT x_value, data_value FROM data";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)){
$x[] = $row['x_value'];
$data[] = $row['data_value '];
}
// use the chart class to build the chart:
include_once( '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( $x );
// set the Y max
$g->set_y_max( 60 );
// label every 10 (0,10,20,30,40,50,60)
$g->y_label_steps( 6 );
// display the data
echo $g->render();
Date :
2010-06-03 09:12:36
By :
kerb
No. 5
Guest
ลองแล้วปรากฏว่า video cannot download คะ ไม่แน่ใจว่าเป็นที่ข้อมูลประกาศผิดไหม
Code (PHP)
<?php
$objConnect = odbc_connect("TH5database","","") or die("Error Connect to Database");
$strSQL = "SELECT 'Time_1H' as x1, '1H'as y1 FROM tbl_EIRP ";
$objExec = odbc_exec($objConnect, $strSQL) or die ("Error Execute [".$strSQL."]");
//$connect = odbc_connect("TH5database", "", "") or die("Unable to connect");
//echo "<br>".$connect."<br>";
while($a=odbc_fetch_array($objExec))
{
//$x[] = $row['Time_1H'];
//$x = odbc_result($objExec,"Time_1H") ;
$x[]=$a['x1'];
//$data[] = $row['1H '];
//$data=odbc_result($objExec,"1H") ;
$data[]=$a['y1'];
}
odbc_close($objConnect);
include 'php-ofc-library/open-flash-chart.php';
$chart = new open_flash_chart();
$title = new title( date("D M d Y") );
$chart->set_title( $title );
$s = new scatter_line( '#FF00FF', 3 );
$def = new hollow_dot();
$def->size(3)->halo_size(2);
$s->set_default_dot_style( $def );
$v=new scatter_value($x,$data);
$s->set_values( $v );
$s->set_key( "Pinky", 16 );
$chart->add_element( $s );
$t = new scatter_line( '#FFAC59', 5 );
$def = new hollow_dot();
$def->size(3)->halo_size(2);
$t->set_default_dot_style( $def );
$v = array(
new scatter_value( 0, -5 ),
new scatter_value( 0.5, -5 ),
new scatter_value( 10, -5 ),
new scatter_value( 10, -7 ),
new scatter_value( 10, -8 )
);
$t->set_values( $v);
$t->set_key( "Night Lovin", 16 );
$chart->add_element( $t );
$u = new scatter_line( '#008080', 3 );
$def = new hollow_dot();
$def->size(3)->halo_size(2);
$u->set_default_dot_style( $def );
$v = array(
new scatter_value( 12, -8 ),
new scatter_value( 25, -8 )
);
$u->set_values( $v );
// LOOK: no key set
//$t->set_key( "Night Lovin", 16 );
$chart->add_element( $u );
$s = new star();
$s->size(6)->halo_size(2);
$line = new line();
$line->set_colour('#1693A5');
$line->set_default_dot_style($s);
$line->set_values(
array(
5,5,10,5,5,
5,5,5,5,5,
5,5,5,5,5,
5,5,5,8,5,
5,5,5,5,5,5 ));
$line->set_width( 2 );
$line->set_key( "I'm blue, baby!", 16);
$chart->add_element( $line );
$x = new x_axis();
$x->set_range( 0, 25 );
$chart->set_x_axis( $x );
$y = new x_axis();
$y->set_range( -10, 10 );
$chart->add_y_axis( $y );
//echo $chart->toPrettyString();
?>
<html>
<head>
<!--<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",
"600", "400", "9.0.0");
</script>
<script type="text/javascript">
function ofc_ready()
{
alert('ofc_ready'); //start your AJAX timer
}
//take the JSON object, make it into a string and pass this string to the chart
function open_flash_chart_data()
{
alert( 'reading data' ); //take the JSON object, make it into a string and pass this string to the chart
return JSON.stringify(data); //converting JavaScript data structures into JSON text ,JSON.stringify(myObject, replacer)
}
function findSWF(movieName) {
if (navigator.appName.indexOf("Microsoft")!= -1) {
return window[movieName];
} else {
return document[movieName];
}
}
var data = <?php echo $chart->toPrettyString(); ?>;
</script>
</head>
<body>
<div id="my_chart"></div>
</body>
</html>