LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-15-2007, 02:05 PM   #1
Tom "Techno" Earl
Member
 
Registered: Sep 2006
Posts: 37

Rep: Reputation: 16
I am trying to design a bar chart of sunspots over time?


Hi All,

I am trying to design a PHP site that will take a number of sunspot groups from a database and the time they were inputted, and display them in a chart, at the moment, I have managed to get it so that it will change the location of the pixel based on number of groups, but not time, so effectively I have an X axis, but no Y axis on my graph.

The current location (at time of writing) is http://www.tomearl.unicorn-group.co.uk/astronomy

When you submit the input form, it inputs the number of groups you specified and the current time using the now() function on the datetime field in the database.

I think I need to convert the time code to Unix time to display them using CSS pixel positioning, I use the mktime() function for that,
The code that I am using is below

index.php
PHP Code:
<html>
<head>
<title>Sunspot Viewer</title>
</head>
<body>

<h1>Tom's handy dandy sunspot viewer!</h1>
<a href="includes/input.php">Insert new record</a>
<hr width="100%" size="1">
<div>

<?php
  
/// Echo how many minutes have passed since script was last tested
  
$test 1171566521 time('U');
  
$finaltest str_replace("-"""$test);
  echo 
$finaltest 60;

  
/// Connect to the database
  
include 'includes/connect.php';

  
/// Start the query
  
$query "SELECT * FROM sunspot_groups";

  
/// Execute the query
  
$result mysql_query($query) or die(mysql_error());

  
/// Start to loop through the results
  
while ($row mysql_fetch_array($result) or die(mysql_error())) {
  
/// Assign the array to variables, and add 100px to height to bring it up off the bottom of the page
  
$groups $row[groups] + 100;
  
$id $row[id];
  
$date $row[date];
  
$adate 1171566521 mktime($row[date]);
  
$udate str_replace("-"""$adate);

  echo 
"<table border=\"0\" style=\"position: absolute; bottom: $groups.0px; left: $udate.0px\"><tr><td><img src=\"includes/pixel.jpg\" height=\"2px\" width=\"2px\">$date</td></tr></table>";

  }

echo 
"

</div>
</body>
</html>
"
;

?>
The connect.php
PHP Code:
<?php

 $conn 
mysql_connect("localhost","user","password");
 
mysql_select_db("database");

?>
input.php
PHP Code:

<?php
  
/// Check to see if the form has been posted
  
if (!$_POST) { 

  
/// It hasn't

?>

<html>
 <head>
  <title>Input you data...</title>
 </head>

 <body>

  <form method="post" action="<?php echo $_SERVER[PHP_SELF]; ?>">
  <h1>Input your data...</h1>

  <p>Number of groups:</p>
  <input type="text" name="groups">
  <input type="submit">

 </body>

</html>

<?php

 
} else {

 
/// connect to the database
 
include 'connect.php';

 
/// Start the query
 
$query "INSERT INTO sunspot_groups VALUES ('', '$_POST[groups]', now())";

 
// execute the query
 
mysql_query($query) or die(mysql_error());

 echo 
"<h1>Done!</h1>";

}
?>
The script I used to create the database
PHP Code:
<?php

 
include 'connect.php';

 
$query1 "CREATE TABLE sunspot_groups (
            id MEDIUMINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
            groups MEDIUMINT NOT NULL DEFAULT'0',
            date DATETIME)"
;

 
mysql_query($query1) or die(mysql_error());

?>
Any help would be greatly appreciated!

Thanks

Tom
 
Old 02-15-2007, 05:06 PM   #2
kscott121
Member
 
Registered: Jul 2003
Location: NC
Distribution: Fedora,Mepis,Debian
Posts: 84

Rep: Reputation: 15
Your coding exceeds my knowledge but I ran across an app that does does the kinds of things you are attempting. It is called Ploticus.
see http://ploticus.sourceforge.net/doc/welcome.html
It is designed for live data, just in time plotting needs.
Check it out. Might help.
 
Old 02-19-2007, 07:51 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
there is of course always gnuplot
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Engine Manufacturer MTU Simplifies Design Workloads and Cuts Admin Time in Half by Using DataCore's Virtualization Software and VMware LXer Syndicated Linux News 0 09-05-2006 03:21 PM
xclock show time in window title bar (using bash?) jaybee Linux - Software 5 06-19-2006 01:27 PM
How to design routing protocol for ad-hoc networks with time guarantee? ArthurHuang Linux - Networking 0 05-04-2006 11:03 PM
LXer: Time to Bar Windows From the Enterprise LXer Syndicated Linux News 0 01-06-2006 10:31 AM
graph and chart design tool cold Linux - Software 2 02-26-2004 01:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration