How to Select Data for Highcharts

'Ello!

Fantastic resource this website is, I’m chugging along on my project, however I am stuck with using the highcharts javascript library.

I’ve downloaded it, and included the proper files (tested with their demo code) so I know that’s in order, but what I am trying to do is generate a query to get user’s miles per gallon data that is stored in a DB and graph it over time (time of entry is also stored).

So, I have two fields of interest: mpg and time which are stored in the table fuelups.

I was thinking about something along the following lines:
[php] $stmt = “SELECT time, mpg FROM fuelups WHERE UID= '” . $_SESSION[‘UID’] . “’ AND mpg IS NOT NULL ORDER BY time ASC”;

$result = mysql_query($stmt); 

while($row = mysql_fetch_array($result)) {   
	echo $row['time'] . "\t" . $row['mpg'] . "\n"; 
}[/php]

I’m not sure what the “\t” operator does, this is code someone told me to try (don’t know what to do next with it) while calling it with jQuery (which I have no experience with) :o :frowning:

So, basically, from select statement I want to be able to graph it but I’m not sure how to define the highcharts information. Should be a simple line graph with miles per gallon as the y-axis and date as the x-axis. Important to note that the x-axis won’t be regular time intervals, as the date/time information is dependent on when the user enters it (i.e. how often they fuel their vehicle).

You are going to need to learn to pull this off :slight_smile:

Have you read this page? There are examples using JSON/XML & jQuery

http://www.highcharts.com/documentation/how-to-use

You can encode PHP arrays to JSON by using the json_encode() function.

The “\t” is nothing more than a tab. Just like “\n” is a new line.

Sponsor our Newsletter | Privacy Policy | Terms of Service