1

I am trying to create a chart with flot using data taken from a mysql database

     <div id="flot-placeholder" style="width:800px;height:450px"></div>
    <?php  
          $host = "localhost";
          $uname = "user";
          $pass = "mypass";
          $database = "mydb";
          $connection=mysql_connect($host,$uname,$pass) or die("connection in not ready <br>");
          $result=mysql_select_db($database) or die("database cannot be selected <br>");

          $sql = mysql_query ("SELECT * FROM dailysales");
          $lineset=array();

          while($lrow = mysql_fetch_assoc($sql)) 
          {
                 $lineset[] = array($lrow['quantity'],$lrow['paid']);
          }

         ?>


 <script language="javascript">
 var plotdata =  <?php echo json_encode($lineset);?>;

 var data,options;

 data=[[plotdata]];

 document.write(plotdata);
 options={};
 $(document).ready(function () {
   $.plot($("#flot-placeholder"),
            data,
    options);
});
</script>

This shows the chart but the chart itself is empty. Printing the value of plotdata does give the correct values as 210,1000.00,30,3500.00. Any help is appreciated.

1 Answer 1

3

Your plotdata is already an array and then you put it in an array twice when assigning it to data. Try

data = [plotdata];

See the documentation for more info.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.