Thivya Posted September 24, 2007 Share Posted September 24, 2007 hello, I have draw a graph using Jpgraph components,able to display the graph as well.Now i want the data that has been used for plotting that graphs also to be displayed at the bottom of the graph.I can display the data in table format but i dont know how can combine both graph codes and codes for the table..the following is the codes for the graph.. <?php $db_name = "wsn"; $table_name = "suhu"; $connection = @mysql_connect("localhost", "", "") or die(mysql_error()); $db = @mysql_select_db($db_name, $connection) or die(mysql_error()); $query = "SELECT Date, AVG(voltage),AVG(Temper), AVG(light),AVG(accel_x), AVG(accel_y), AVG(mag_x), AVG(mag_y), AVG(mic) from suhu WHERE Date >= '{$_POST['Year']}-{$_POST['Month']}-01' and Date <= '{$_POST['Year']}-{$_POST['Month']}-31' group by `Date` "; $result = mysql_query($query) or die(mysql_error()); include ("c:/jpgraph-1.21b/src/jpgraph.php"); include ("c:/jpgraph-1.21b/src/jpgraph_Line.php"); while($row = mysql_fetch_array($result)) { $data[] = $row["AVG(mag_x)"]; $leg[] = $row["AVG(mag_y)"]; } $graph = new Graph(1000,1000); $graph->SetScale("textint"); $graph->img->SetMargin(50,30,50,50); //$graph->SetBackgroundImage("Blue hills.jpg",BGIMG_FILLFRAME); $graph->SetShadow(); $graph->xaxis->SetTickLabels($leg); $lplot = new LinePlot($data); $lplot->SetFillColor("lightgreen"); // Fill color $lplot->value->Show(); $lplot->value->SetFont(FF_ARIAL,FS_BOLD); $lplot->value->SetAngle(45); $lplot->value->SetColor("black","navy"); $lplot->SetLegend("Light"); $graph->title->Set("Light based on selected month"); $graph->xaxis->title->Set("mag_x"); $graph->yaxis->title->Set("mag_y"); $graph->title->SetFont(FF_FONT1,FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD); $graph->Add($lplot); $graph->Stroke(); ?> And this the codes this is the code that i use to display the data in table format. <? //set up database and table names $username = ""; // change this to your username $password = ""; // change this to your password $link = @mysql_connect ($server, $username, $password) or die (mysql_error()); /* Defines the Active Database for the Connection */ if (!@mysql_select_db("wsn", $link)) { echo "<p>There has been an error. This is the error message:</p>"; echo "<p><strong>" . mysql_error() . "</strong></p>"; echo "Please Contact Your Systems Administrator with the details"; } /* Sets the SQL Query */ $sql = "SELECT Node_ID , AVG(voltage),AVG(Temper), AVG(light),AVG(accel_x), AVG(accel_y), AVG(mag_x), AVG(mag_y), AVG(mic),Date from suhu "; $sql .= " WHERE (suhu.Date ='{$_POST['calendar']}')group by Node_ID"; /* Passes a Query to the Active Database */ $result = mysql_query($sql, $link); $num=@mysql_num_rows($result); if($num<1) { $mesg = "SORRY!!! NO RECORDS BY THIS NAME<P>PLEASE TRY ANOTHER"; header( "Location: http://localhost/PEDWSN/message.php?mesg=$mesg"); exit; } /* Starts the table and creates headings */ ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Performance and Visualization Of Wireless Sensor Network-Main Page</title> <style type="text/css"> <!-- body { background-color: #FFFFFF; } .style5 { font-family: "Courier New", Courier, mono; color: #000000; font-size: 18px; font-weight: bold; } .style6 {font-family: "Courier New", Courier, mono; color: #0000FF; font-size: 18px; font-weight: bold; } .style7 {font-size: 24px} .style8 {font-family: "Courier New", Courier, mono; color: #0000FF; font-size: 24px; font-weight: bold; } .style11 {color: #0000FF} .style12 {font-size: 24px; font-family: "Courier New", Courier, mono; } --> </style></head> <body> <p> <img src="image/logo.jpg" width="208" height="201"> <img src="image/text2.jpg" width="701" height="80"></p> <p> <center> <img src="image/frame1.jpg" width="1051" height="51"><? echo "$display_block";?> <table> <tr> <td><strong> Date </strong></td> <td><strong>Nodes </strong></td> <td><strong>Volts </strong></td> <td><strong>Temperature </strong></td> <td><strong>Light </strong></td> <td><strong>accel_x </strong></td> <td><strong>accel_y </strong></td> <td><strong>mag_x </strong></td> <td><strong>mag_y </strong></td> <td><strong>mic </strong></td> </tr> <? /* Retrieves the rows from the query result set and puts them into a HTML table row */ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo("<tr>\n\n<td> " . $row["Date"] . " </td>"); echo("<td>\n" . $row["Node_ID"] . " </td>\n"); echo("<td>\n" . $row["AVG(voltage)"] . " </td>\n"); echo("<td>\n" . $row["AVG(Temper)"] . " </td>\n"); echo("<td>\n" . $row["AVG(light)"] . " </td>\n"); echo("<td>\n" . $row["AVG(accel_x)"] . " </td>\n"); echo("<td>\n" . $row["AVG(accel_y)"] . " </td>\n"); echo("<td>\n" . $row["AVG(mag_x)"] . " </td>\n"); echo("<td>\n" . $row["AVG(mag_y)"] . " </td>\n"); echo("<td>\n" . $row["AVG(mic)"] . " </td>\n"); } /* Closes the table */ ?> </p> </center></p> <table width="440" border="0" align="center"> <tr> <td width="103" class="style11"><span class="style12"> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="22"> <param name="movie" value="BckViewDetails.swf"> <param name="quality" value="high"> <embed src="BckViewDetails.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100" height="22" ></embed> </object> </span></td> <td width="103" class="style11"><p align="center" class="style12"> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="22"> <param name="movie" value="Print.swf"> <param name="quality" value="high"> <embed src="Print.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100" height="22" ></embed> </object> </p></td> <td width="100" class="style11"> </td> <td width="106" class="style11"> </td> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> </tr> </table> <div align="center" class="style11"></div> <p align="left" class="style11"> </p> </body> </html> Now i come up with this codes to display the desired output..but it shows error... <?php $db_name = "wsn"; $table_name = "suhu"; $connection = @mysql_connect("localhost", "", "") or die(mysql_error()); $db = @mysql_select_db($db_name, $connection) or die(mysql_error()); $query = "SELECT Date, AVG(voltage),AVG(Temper), AVG(light),AVG(accel_x), AVG(accel_y), AVG(mag_x), AVG(mag_y), AVG(mic) from suhu WHERE Date >= '{$_POST['Year']}-{$_POST['Month']}-01' and Date <= '{$_POST['Year']}-{$_POST['Month']}-31' group by `Date` "; $result = mysql_query($query) or die(mysql_error()); include ("c:/jpgraph-1.21b/src/jpgraph.php"); include ("c:/jpgraph-1.21b/src/jpgraph_Line.php"); while($row = mysql_fetch_array($result)) { $data[] = $row["AVG(mag_x)"]; $leg[] = $row["AVG(mag_y)"]; } $graph = new Graph(1000,1000); $graph->SetScale("textint"); $graph->img->SetMargin(50,30,50,50); //$graph->SetBackgroundImage("Blue hills.jpg",BGIMG_FILLFRAME); $graph->SetShadow(); $graph->xaxis->SetTickLabels($leg); $lplot = new LinePlot($data); $lplot->SetFillColor("lightgreen"); // Fill color $lplot->value->Show(); $lplot->value->SetFont(FF_ARIAL,FS_BOLD); $lplot->value->SetAngle(45); $lplot->value->SetColor("black","navy"); $lplot->SetLegend("Light"); $graph->title->Set("Light based on selected month"); $graph->xaxis->title->Set("mag_x"); $graph->yaxis->title->Set("mag_y"); $graph->title->SetFont(FF_FONT1,FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD); $graph->Add($lplot); $graph->Stroke(); while($row = mysql_fetch_array($result)){ echo("<tr>\n\n<td> " . $row["Date"] . " </td>"); echo("<td>\n" . $row["Node_ID"] . " </td>\n"); echo("<td>\n" . $row["AVG(voltage)"] . " </td>\n"); echo("<td>\n" . $row["AVG(Temper)"] . " </td>\n"); echo("<td>\n" . $row["AVG(light)"] . " </td>\n"); echo("<td>\n" . $row["AVG(accel_x)"] . " </td>\n"); echo("<td>\n" . $row["AVG(accel_y)"] . " </td>\n"); echo("<td>\n" . $row["AVG(mag_x)"] . " </td>\n"); echo("<td>\n" . $row["AVG(mag_y)"] . " </td>\n"); echo("<td>\n" . $row["AVG(mic)"] . " </td>\n"); } ?> How i can combine this both codes ,to produce both graphs and the data in table format?Could someone please help me... Thank you for the time... Quote Link to comment https://forums.phpfreaks.com/topic/70413-how-to-display-the-graph-with-the-data-in-one-pagehelp-needed/ Share on other sites More sharing options...
Barand Posted September 24, 2007 Share Posted September 24, 2007 I don't use JPGraph, but try putting the code for the graph in a separate file, say, "graph.php" In the other page, put an image tag where you want the graph <img src="graph.php"> Quote Link to comment https://forums.phpfreaks.com/topic/70413-how-to-display-the-graph-with-the-data-in-one-pagehelp-needed/#findComment-353843 Share on other sites More sharing options...
Thivya Posted September 25, 2007 Author Share Posted September 25, 2007 Yes it works.... Now i have another problem with the coding... The graph actually will be generated by the start and the end date that was selected bt the user,i named that page as Search_date..then i by using the post method ,i post this page to another page i named it Data_Display(to display data only)..I did the same thing for drawing graph also from one page(user select tha date,to view graph for that date) to another page(this page will have coding for drawing the graph).... Now ,what i am expecting to do this from 1 page(the user select date),it will post to both pages which one is for display data and the other one for drawing graph... Then in the display_data page i will put code this code Code: <img src="graph.php"> then both data and the graph will be displayed... When i try it doesnt work ,because cant post one page to two pages.....So what the output that i can get is only the data being displayed,but as for the graphs...error message from Jpgraph saying no data is being selected to plot the data" This is because information from Search_Data was not post to graph page...thats why no points being selected for plotting the graph.... I am not sure whether my question is clear enough or not?? Briefly "How to display graph(dynamic,because it will change according to what date the user choose) with data ?" Is there any other suggestion? thank you for your time..... Quote Link to comment https://forums.phpfreaks.com/topic/70413-how-to-display-the-graph-with-the-data-in-one-pagehelp-needed/#findComment-354690 Share on other sites More sharing options...
Barand Posted September 25, 2007 Share Posted September 25, 2007 pass variables to graph.php via the query string <img src="graph.php?id=$xyz"> Quote Link to comment https://forums.phpfreaks.com/topic/70413-how-to-display-the-graph-with-the-data-in-one-pagehelp-needed/#findComment-354787 Share on other sites More sharing options...
Thivya Posted September 27, 2007 Author Share Posted September 27, 2007 I did some changes as below... <? echo '<src image="Graph.php?suhu.Date='_POST['calendar']' ">'; ?> I got parse error as follows... Parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';' in C:\Program Files\xampp\htdocs\PEDWSN\Search_Data.php on line 71 How to detect this error?Could you please the codes,did i missed anything?Is the code is correct? and i changed the sql command at graph.php as below.. $query = "SELECT Node_ID , AVG(voltage),AVG(Temper), AVG(light),AVG(accel_x), AVG(accel_y), AVG(mag_x), AVG(mag_y), AVG(mic),Date from suhu WHERE (suhu.Date ='{$_GET[['calendar']}')group by Node_ID"; thank you for your time... Quote Link to comment https://forums.phpfreaks.com/topic/70413-how-to-display-the-graph-with-the-data-in-one-pagehelp-needed/#findComment-356121 Share on other sites More sharing options...
d.shankar Posted September 27, 2007 Share Posted September 27, 2007 Try this echo "<src image=Graph.php?suhu.Date=".$_POST['calendar'].">"; Quote Link to comment https://forums.phpfreaks.com/topic/70413-how-to-display-the-graph-with-the-data-in-one-pagehelp-needed/#findComment-356203 Share on other sites More sharing options...
Thivya Posted September 29, 2007 Author Share Posted September 29, 2007 hai... I got the answer ready...Actually it should be like this? <? echo "<img src=\"Specific_Temperature_Line_Graph.php?calendar={$_POST['calendar']}\">"; ?> Now to pass a value that has a start and end value,how the codes should be?Referrint to the below sql command i have to get value for all details between the start and end date.... $sql = "SELECT Node_ID , AVG(voltage),AVG(Temper), AVG(light),AVG(accel_x), AVG(accel_y), AVG(mag_x), AVG(mag_y), AVG(mic),Date from suhu "; $sql .= " WHERE (suhu.Date ='{$_POST['calendar']}')group by Node_ID"; I come up with the below codes...it never produces any ouput...neither errors displayed as well.. <? echo "<img src=\"Specific_Temperature_Line_Graph.php?start={$_POST['start']}=> {$_POST['end']}&&calendar3={$_POST['calendar3']}<={$_POST['calendar3']} \">"; ?> Meaning that the syntax is wrong ,or somethg wrong in the ">,<"?? Help me to review this codes....thank you in advance... Quote Link to comment https://forums.phpfreaks.com/topic/70413-how-to-display-the-graph-with-the-data-in-one-pagehelp-needed/#findComment-357660 Share on other sites More sharing options...
Barand Posted September 29, 2007 Share Posted September 29, 2007 <?php echo "<img src=\"Specific_Temperature_Line_Graph.php?start={$_POST['start']}&end={$_POST['end']}&calendar3={$_POST['calendar3']}\">"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/70413-how-to-display-the-graph-with-the-data-in-one-pagehelp-needed/#findComment-357778 Share on other sites More sharing options...
Thivya Posted September 30, 2007 Author Share Posted September 30, 2007 hello, Thanks for the given codes...but sorry,i mistakenly add the the word 'start' and 'end' in my previous codes...actuatually i assume start as calendar3 and end as calendar3 ...Just ingore the start and end date... It is something like this ..generate a graphs that is between the date captured by calendar 2(start date) and calendar 3(end date)..calendar2 and calendar3 is the javapicker in my forms.From the selected dates between calendar2 and calendar 3,the graphs will generated... As for this code,graphs will be generated for that one specfic date only...where the date picked by calendar [code]<? echo "<img src=\"Specific_Temperature_Line_Graph.php?calendar={$_POST['calendar']}\">"; ?> <?php echo "<img src=\"Specific_Temperature_Line_Graph.php?start={$_POST['start']}&end={$_POST['end']}&calendar3={$_POST['calendar3']}\">"; ?> This is the code that you provide..Seems my previous questions include the start and end date,you have inserted the start and end date as well...Actually in my real coding here i just assume calendar2 as (start) and calendar3 as (end)... So,with only having calendar2 and calendar 3....how the codes will be?Is it something like this? <?php echo "<img src=\"Specific_Temperature_Line_Graph.php?start={$_POST['start']}&end={$_POST['end']\">"; ?>[/code] Could you please explain which syntax has been used to show (BETWEEN)..seems the it should generate graph between calendar2(start date) and calendar3(end date)? Sorry again for the wrong information... thank you for your time... Quote Link to comment https://forums.phpfreaks.com/topic/70413-how-to-display-the-graph-with-the-data-in-one-pagehelp-needed/#findComment-358267 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.