...

View Full Version : PHP/SWF charts



SDonovan
08-11-2008, 08:49 PM
I have been spinning my wheels all day on this.

The tutorial says the following:

1. Type the following text in a text document, name the document sample.php, and place it on your server:

<?php

//include charts.php to access the SendChartData function
include "charts.php";

SendChartData ();

?>

Mine is called discriminator.php

I am just testing trying to get it working before I query from my database.

Here it is:


<?php

include "charts.php";

//the chart's data
$chart [ 'chart_data' ] = array ( array ( "", "2001", "2002", "2003", "2004" ),
array ( "Region A", 5, 10, 30, 63 ),
array ( "Region B", 100, 20, 65, 55 ),
array ( "Region C", 56, 21, 5, 90 )
);

//send the new data to charts.swf
SendChartData ( $chart );
?>

charts.php is in the same directory as discriminator.php

How can I use InsertChart along with a javascript popup function like so?


<input type="button" value="&nbsp;Discriminator&nbsp;" onclick="popUp(\''.append_sid('charts.swf', 'charts_library', 'discriminator.php').'\', 500, 350)">&nbsp;&nbsp;

The tutorial has something like so:


<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>

I want to combine the two. Any help is appreciated.

mlseim
08-12-2008, 01:06 PM
If you use the last code you listed (the tutorial) that has this line,
echo InsertChart ( "charts.swf", "charts_library", "sample.php", 400, 250 );

... and you put your script name in there (discriminator.php instead of sample.php),
does that work? I think you should make sure it works before going any further.

I was wondering what "charts_library" is ... did they say what that was?

SDonovan
08-12-2008, 01:30 PM
I have several buttons along the bottom of this page. I can't insert a chart in the middle of these buttons. I don't need a popup but do need this to work with an onclick event. Here is what the block of code looks like.


$template->assign_block_vars('quiz_report.info',array('Q_INFO' => '<input type="button" value="&nbsp;Test&nbsp;" onclick="popUp(\''.append_sid('test_stats.php?ARG1='.$cid.'&ARG2='.$qid).'\', 800,500,1,1)">&nbsp;&nbsp;
<input type="button" value="&nbsp;Histogram&nbsp;" onclick="popUp(\''.append_sid('histogram.php?ARG1='.$cid.'&ARG2='.$qid).'\', 800,500,1,1)">&nbsp;&nbsp;

<input type="button" value="&nbsp;Discriminator&nbsp;" onclick="javascript:window.location=\''.InsertChart('charts.swf', 'charts_library', 'discriminator.php').'\'">&nbsp;&nbsp;

<input type="button" value="Students" onclick="popUp(\''.append_sid('student_report.php?ARG1='.$cid.'&ARG2='.$qid.'&ARG3=0').'\', 800,500,1,1)">&nbsp;&nbsp;
<input type="button" value="Multiple Choice Questions" onclick="popUp(\''.append_sid('question_report.php?ARG1='.$cid.'&ARG2='.$qid.'&ARG3='.$course_quiz['year_used']).'\', 660,510,1,1)">&nbsp;&nbsp;
<input type="button" value="Score Sheet" onclick="popUp(\''.append_sid('student_score.php?ARG1='.$cid.'&ARG2='.$qid.'&ARG3=0').'\', 600,550,1,1)">&nbsp;&nbsp;'
, 'Q_INPUT' => ''));

Do I need a third page called discriminator_output.php where I point the


onclick="popUp(\''.append_sid('discriminator_output.php')">

Then from there call:


echo InsertChart ( "charts.swf", "charts_library", "discriminator.php", 400, 250 );

My problem is trying to combine these functions popUp, append_sid and InsertChart.

SDonovan
08-12-2008, 06:50 PM
Well I got a sample chart to appear.


<input type="button" value="&nbsp;Discriminator&nbsp;" onclick="popUp(\''.append_sid('discriminator_output.php?ARG2='.$qid).'\', 800,500,1,1)">&nbsp;&nbsp;

Now comes my data.

I have studied the tutorial for PHP/SWF graphs and this is what it is doing:

The have a table from the accounting database called growth.

From the growth table they have region, year, and revenue.


Region Year Revenue
Region A 2001 5
Region A 2002 10
Region A 2003 30
Region A 2004 63
Region B 2001 100

They organize it into a multidimensional array.


//start the PHP multi-dimensional array and create the region titles
$chart [ 'chart_data' ][ 0 ][ 0 ] = "";
$chart [ 'chart_data' ][ 1 ][ 0 ] = "Region A";
$chart [ 'chart_data' ][ 2 ][ 0 ] = "Region B";
$chart [ 'chart_data' ][ 3 ][ 0 ] = "Region C";

//connect to the database
mysql_connect ( "host", "user", "password" );
mysql_select_db ( "Accounting" );

//get the smallest year to determine which year to start the chart with
$result = mysql_query ( "SELECT MIN(Year) AS MinYear FROM Growth" );
$MinYear = mysql_result ( $result, 0, "MinYear" );

//get all the data in the Growth table
$result = mysql_query ("SELECT * FROM Growth");

//extract the data from the query result one row at a time
for ( $i=0; $i < mysql_num_rows($result); $i++ ) {

//determine which row in the PHP array the current data belongs to
switch ( mysql_result ( $result, $i, "Region" ) ) {
case "Region A":
$row = 1;
break;

case "Region B":
$row = 2;
break;

case "Region C":
$row = 3;
break;
}

//determine which column in the PHP array the current data belongs to
$col = mysql_result ( $result, $i, "Year") - $MinYear + 1;

//populate the PHP array with the Year title
$chart [ 'chart_data' ][ 0 ][ $col ] = mysql_result ( $result, $i, "Year");

//populate the PHP array with the revenue data
$chart [ 'chart_data' ][ $row ][ $col ] = mysql_result ( $result, $i, "Revenue");
}



My data is from a quiz_stats table.

I have only two values.. question_id and discri.

The discri is called a discriminator and it is a value that gives a performance based on how well the question is does during a test.

I want to graph this the same way they are graphing revenue.

My Y axis would be the number of questions that fall into each range.

The X axis would be a range such as this in a case statement:



//get all the data in the QUESTION_STATS table
$getall = $db->sql_query("SELECT * FROM ". QUESTION_STATS_TABLE." WHERE quiz_id = '$qid'");

//extract the data from the query result one row at a time
for ( $i=0; $i < $db->sql_numrows($getall); $i++ ) {

switch ( $db->sql_fetchrow ( $getall, $i, "discri" ) ) {
case ($discri <= -.4 AND $discri >= -.31): //less than -.4 and greater or equal to -.31
$row = 1;
break;

case ($discri <= -.3 AND $discri >= -.21): //less than or equal to -.3 and greater or equal to -.21
$row = 2;
break;

case ($discri <= -.2 AND $discri >= -.11): //less than or equal to -.2 and greater or equal to -.11
$row = 3;
break;

case ($discri <= -.1 AND $discri >= -.01): //less than or equal to -.1 and greater or equal to -.01
$row = 4;
break;

case ($discri <= 0 AND $discri >= .09): //less than or equal to .1 and greater or equal to .09
$row = 5;
break;

case ($discri <= .10 AND $discri >= .19): //less than or equal to .1 and greater or equal to .19
$row = 6;
break;

case ($discri <= .20 AND $discri >= .29): //less than or equal to .2 and greater or equal to .29
$row = 7;
break;

case ($discri <= .30 AND $discri >= .39): //less than or equal to .3 and greater or equal to .39
$row = 8;
break;

case ($discri <= .40 AND $discri >= .49): //less than or equal to .4 and greater or equal to .49
$row = 9;
break;
}

}

Since I only have two data values I'm thinking I need an associative array.

How could I restructure their example to accomplish what I want?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum