Alex Rivera | Logout

Retrieve data from mysql by php to create flot graph

Asked 2009-08-21T14:30:16.713
12

Hi i am trying to retrieve data from mysql database to create flot graph can anyone walk me through this procedure or give me an idea of what to do thanks

Edit
Report

2 Answers

22

You probably want something like this. I haven't used flot but I looked at the example here.

<?php
//create array of pairs of x and y values
$dataset1 = array();
while ($row = mysql_fetch_assoc()) { //or whatever
    $dataset1[] = array( $row['xvalue'], $row['yvalue'] );
}
?>

<script type="text/javascript">
    //put array into javascript variable
    var dataset1 = <?php echo json_encode($dataset1); ?>;

    //plot
    $(function () {
         $.plot($("#placeholder"), [ dataset1 ]);
    });
</script>
answered 2009-08-21T14:54:06.533
0

This depends largely on your environment and requirements. There's lots of free tools out there you can use. One example is Flot that lets you use jQuery to build graphs. There's link to documentation on the Google Code page.

answered 2009-08-21T14:48:39.227

Your Answer