Jump to content

Need help with graph


lanredoyes

Recommended Posts

Hello,

 

Please i need help using jpgraph or rpgraph. I am working on a php/mysql project that as to do with graphing. The issue is not to be able get both graphing solution to work or pull data from the database as i have been able to do that from their provided documentation, the issue is allowing the user to be able to query the database through a form on the page.

 

I have a large database with fields like 'state', 'year', 'month', 'readings', and i want the user to be able to query the db themselves so as to get the very graph they want. the form the user will see will have the four fields both on the x and y axis so that when the user select a particular year against the readings only the values of each month of that year will be displayed.

 

The look of the form has been attached. Really appreciate a response as i am very desperate about this now.

 

Many thanks.

post-139484-0-97941900-1360395033_thumb.jpg

Link to comment
Share on other sites

Get the data from the submitted fields

$state = $_POST['state'] // etc

 

Put an img tag where you want to display the graph

<img src='graph.php?state=$state&year=$year&month=$month' />

 

passing the form data in the querystring to your graph generating php file

Edited by Barand
Link to comment
Share on other sites

Thanks very much for the quick response but i really dont quit understand. So please let me get you right. The form action will be self and in the action, each field will be called by $state //etc and in the section where the graph will appear, the img tag should be there.

 

If i may ask, can you pls help me with the structure of the form action as i am kinda clueless.

 

Many thanks and i greatly appreciate

Link to comment
Share on other sites

Hello, thanks for response really appreciate it. Firstly I must say i am a newbie to php and all i know presently is through associated documentation of the script/software. I have please attached the code to my html form below.

 

<form id="form" action="#" method="post" name="form">
<table width="50%" border="0" cellspacing="0" cellpadding="0">

<tr>
 <td colspan="6" align="center"><strong>Draw Graph</strong></td>
 </tr>
 <tr>
 <td colspan="6" align="left"><strong>X-Axis:</strong></td>
 </tr>
 <tr>
 <td width="90" align="left"><label for="state"><strong>State:</strong></label></td>
 <td width="166" align="left"><select name="state" id="state" value="">
   <option value="Select All">Select All</option>
   <option value="FCT">FCT</option>
   <option value="Abia">Abia</option>
   <option value="Adamawa">Adamawa</option>
   <option value="Akwa-Ibom">Akwa-Ibom</option>
   <option value="Anambra">Anambra</option>
   <option value="Bauchi">Bauchi</option>
   </select></td>
 <td width="94" align="left"><label for="year_of_record"><strong>Year:</strong></label></td>
 <td width="134" align="left"><select name="year_of_record" id="year_of_record" value="">
   <option value="Select All">Select All</option>
   <option value="2010">2010</option>
   <option value="2011">2011</option>
   <option value="2012">2012</option>
   <option value="2013">2013</option>
   <option value="2014">2014</option>
   <option value="2015">2015</option>
   <option value="2016">2016</option>
   </select></td>
 <td width="95" align="left"><label for="month_of_record"><strong>Month:</strong></label></td>
 <td width="210" align="left"><select name="month_of_record" id="month_of_record" value="">
 <option value="Select All">Select All</option>
 <option value="January">January</option>
 <option value="February">February</option>
 <option value="March">March</option>
 <option value="April">April</option>
 <option value="May">May</option>
 <option value="June">June</option>
 <option value="July">July</option>
 <option value="August">August</option>
 <option value="September">September</option>
 <option value="October">October</option>
 <option value="November">November</option>
 <option value="December">December</option>
</select></td>
</tr>
<tr>
 <td colspan="3" align="right"></td>
 <td colspan="3"></td>
</tr>

<tr>
<td colspan="3" align="right"></td>
<td colspan="3"></td>
</tr>

<tr>
 <td align="left"><label for="value_of_reading"><strong>Value of Reading:</strong></label>    </td>
 <td align="left"><input name="value_of_reading" maxlength="100" type="text" size="50" value="All Values"></td>
 <td colspan="5" align="left"> </td>
 </tr>
<tr>
 <td colspan="3" align="right"></td>
 <td colspan="3"></td>
</tr>

<tr>
<td colspan="3" align="right"></td>
<td colspan="3"></td>
</tr>

<tr>
 <td colspan="6" align="left"> </td>
 </tr>

<tr>  
<td colspan="6" align="left"><strong>Y-Axis:</strong></td>
 </tr>
 <tr>
 <td width="90" align="left"><label for="state"><strong>State:</strong></label></td>
 <td width="166" align="left"><select name="state" id="state" value="">
   <option value="Select All">Select All</option>
   <option value="FCT">FCT</option>
   <option value="Abia">Abia</option>
   <option value="Adamawa">Adamawa</option>
   <option value="Akwa-Ibom">Akwa-Ibom</option>
   <option value="Anambra">Anambra</option>
   <option value="Bauchi">Bauchi</option>
   </select></td>
 <td width="94" align="left"><label for="year_of_record"><strong>Year:</strong></label></td>
 <td width="134" align="left"><select name="year_of_record" id="year_of_record" value="">
   <option value="Select All">Select All</option>
   <option value="2010">2010</option>
   <option value="2011">2011</option>
   <option value="2012">2012</option>
   <option value="2013">2013</option>
   <option value="2014">2014</option>
   <option value="2015">2015</option>
   <option value="2016">2016</option>
   </select></td>
 <td width="95" align="left"><label for="month_of_record"><strong>Month:</strong></label></td>
 <td width="210" align="left"><select name="month_of_record" id="month_of_record" value="">
 <option value="** Select **">** Select **</option>
 <option value="January">January</option>
 <option value="February">February</option>
 <option value="March">March</option>
 <option value="April">April</option>
 <option value="May">May</option>
 <option value="June">June</option>
 <option value="July">July</option>
 <option value="August">August</option>
 <option value="September">September</option>
 <option value="October">October</option>
 <option value="November">November</option>
 <option value="December">December</option>
</select></td>
</tr>
<tr>
 <td colspan="3" align="right"></td>
 <td colspan="3"></td>
</tr>

<tr>
<td colspan="3" align="right"></td>
<td colspan="3"></td>
</tr>

<tr>
 <td align="left"><label for="value_of_reading"><strong>Value of Reading:</strong></label>    </td>
 <td align="left"><input name="value_of_reading" maxlength="100" type="text" size="50" value="All Values"></td>
 <td colspan="5" align="left"> </td>
 </tr>

<tr>
 <td colspan="6" align="center"><input type="submit" value="Draw Graph"></td>
</tr>

</table>
</form>

 

Here is the current schematic of the database.

 

-----------------------------------------------------------------------------------

| First_Name | Last_Name | Class | State | Year | Month | Record | Marking_Scheme |

-----------------------------------------------------------------------------------

| | | | Osun | 2010 | March | 23 | Drudgery |

-----------------------------------------------------------------------------------

| | | | Edo | 2012 | April | 56 | Drudgery |

-----------------------------------------------------------------------------------

| | | | Osun | 2010 | June | 110 | Maxfield |

-----------------------------------------------------------------------------------

| | | | Niger | 2009 | July | 87 | Drudgery |

-----------------------------------------------------------------------------------

 

As from the schematic, there is only one database storing values for

1. Different State

2. Different year for each state

3. The twelve months for each year

4. Individual Records for each month

5. Each record gotten with peculiar scheme

 

What i am hoping to achieve is a situation whereby the user can use the html form to generate a graph for a particular state and year using a particular marking_scheme whereby the graph of the months of the year against the records will be provided.

 

I know I have not been this explanatory from the beginning but I have been stressed of late as project submission deadline is fast approaching.

 

Many thanks in anticipation of your assistance.

Link to comment
Share on other sites

What will the graphs look like? It's unusual to have Y-axis same as X-axis.

 

Also you use the same name for x-axis state and y-axis state. You will only get the second one posted.

 

I see you have month names - how do expect to ever sort the the data in date order (Apr comes before Jan)? Better to store dates as a single DATE type field (format YYYY-MM-DD)

Link to comment
Share on other sites

Thanks, seriously i really appreciate your responses. The idea is to have a graph of month versus records for a particular year using a particular marking_scheme. I am really lost as to how to get everything right.

 

Please your assistance and clearance will be appreciated as this represents 30% of my school grade work.

Link to comment
Share on other sites

Thanks sirs for your comments so far. @Mittineague, appreciate your advise greatly, but here in Nigeria, some lecturers believes they are demi-gods and won't listen to any plea whatsoever.

 

About the project, I have been able to create a way to populate database data on the browser as in form a report whereby users can then query it and get the limited data they want on the browser through the help of some tutorials gotten.

 

With the graph, i then intend that the user enters the data from the query into the form themselves. However, I am having issues to get the script pull from the form. @Cups, I used the get method as suggested and without the graph script, the form is working with the exception of the textarea field.

 

Please i need help as to how to get this final stage to work as this is almost the final stage of my project.

 

Many Thanks. My code is below:

 

<?php
if(isset($_GET['submit']))
{
$title = (int)$_GET['title']; 
    $legend = (int)$_GET['legend'];
}

// content="text/plain; charset=utf-8"
// Example for use of JpGraph, 
// ljp, 01/03/01 20:32
require_once ('../jpgraph.php');
require_once ('../jpgraph_bar.php');

// We need some data
$datay=array(-0.36,0.25,-0.21,0.43,0.31,0.04,-0.23,0.031,0.29,-0.08,0.07,0.19);

// Setup the graph. 
$graph = new Graph(1000,400); 
$graph->img->SetMargin(60,150,30,50);
$graph->SetScale("textlin");
$graph->SetMarginColor("silver");
$graph->SetShadow();

// Set up the title for the graph
$graph->title->Set("$title");
$graph->title->SetFont(FF_VERDANA,FS_NORMAL,16);
$graph->title->SetColor("darkred");

// Setup font for axis
$graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,10);
$graph->yaxis->SetFont(FF_VERDANA,FS_NORMAL,10);

// Show 0 label on Y-axis (default is not to show)
$graph->yscale->ticks->SupressZeroLabel(false);

// Setup X-axis labels
$graph->xaxis->SetTickLabels($gDateLocale->GetShortMonth());
$graph->xaxis->SetLabelAngle(50);

// Set X-axis at the minimum value of Y-axis (default will be at 0)
$graph->xaxis->SetPos("min"); // "min" will position the x-axis at the minimum value of the Y-axis

// Create the bar pot
$bplot = new BarPlot($datay);
$bplot->SetWidth(0.6);
$bplot->SetLegend("$legend","blue");

// Setup color for gradient fill style 
$bplot->SetFillGradient("navy","steelblue",GRAD_MIDVER);

// Set color for the frame of each bar
$bplot->SetColor("navy");
$graph->Add($bplot);

// Finally send the graph to the browser
$graph->Stroke();
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p>
<form id="form1" name="form1" method="get" action="<?= $PHP_SELF ?>">
 <label for="title">Graph Title:</label><br/>
 <input type="text" name="title" id="title" /><br/><br/>
 <label for="legend">Graph Legend:</label><br/>
 <input type="text" name="legend" id="legend" /><br/><br/>
 <label for="values">Enter X values(seperate with comma):</label><br/>
 <textarea name="values" id="values" cols="45" rows="5"></textarea><br/><br/>
<input type="submit" name="generate" id="generate" value="Generate Graph" />
</form>
</p>
</body>
</html>

Edited by lanredoyes
Link to comment
Share on other sites

About the project, I have been able to create a way to populate database data on the browser as in form a report whereby users can then query it and get the limited data they want on the browser through the help of some tutorials gotten.

 

With the graph, i then intend that the user enters the data from the query into the form themselves.

 

Users love it when you output data for them to re-enter

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.