Draw bar chart using jquery sparkline and mysql data

I am trying to use jquery sparkline with mysql data to show how much money each user makes every day ... Here I will show you money about one example user that is in mysql database:

[{"m":"01 noviembre 2014","d":"15.00"},{"m":"02 noviembre 2014","d":"200.00"},{"m":"03 noviembre 2014","d":"25.00"}]

      

but show nothing ... can you help me and show me where my mistake is?

This is the JS library I am using to try and show the graph:

<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/jquery.sparkline.min.js" type="text/javascript"></script>

      

Here's the javascript on the page:

<?php include_once('graficas/users.php'); ?>
<script type="text/javascript">
    $(function() {
        var myvalues = <?php echo json_encode($users);?>;
        $('.dynamicsparkline').sparkline(myvalues);
        $('.dynamicbar').sparkline(myvalues, {type: 'bar', barColor: 'blue'} );
    });
</script>

      

Here's the code in users.php

<?php
include 'cons.php';
$sql = $conn->prepare("SELECT DATE_FORMAT(start, '%d %M %Y') AS date, SUM(abono) AS total_diario 
FROM GANANCIAS WHERE id_user = '1' AND YEAR(start) = YEAR(current_date) GROUP BY date ASC ORDER BY YEAR(start) ASC");
    $sql->execute();
    while($row = $sql->fetch(PDO::FETCH_ASSOC)) {
    $doctores[] = array('m'=>$row['date'], 'd'=>$row['total_diario']);
}
?>

      

And for the last id to display the chart:

<p>
   <span class="dynamicbar">Loading..</span>
</p>

      

always show only loading ...


EDIT

I changed this piece of code inside user.php

$doctores[] = array('m'=>$row['date'], 'd'=>$row['total_diario']);

      

TO

doctores[] = $row['total_diario'];

      

And now show me a graph with these values:

var myvalues=["25.00","25.00","20.00","15.00"]

      

But the graph is shown with each separated number and dots .... ", 2.5,., 0.0,", .... etc.

fuck! Now it works correctly and will show me all the data for the user!

+3


source to share


1 answer


I changed this piece of code inside users.php

$doctores[] = array('m'=>$row['date'], 'd'=>$row['total_diario']);

      

FROM

doctores[] = $row['total_diario'];

      



And now show me a graph with these values:

var myvalues=["25.00","25.00","20.00","15.00"]

      

But the graph is displayed with each separated number and dots .... ", 2.5,., 0.0,", .... etc.

fig! Now it works correctly and show me all the data for the user!

0


source







All Articles