3

I am trying to use jquery sparkline with mysql data for showing how much money every user make in every day... Here I show you the money about one user example which is in the mysql DB:

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

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

This is the JS library I am use to try to 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 the javascript in 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 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 last the id to show the graph:

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

always show me only loading...


EDIT

I changed this part of the code inside of users.php

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

TO

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

And now show me the graph with these values:

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

But the graph is showed with every separated numbers and dots.... ", 2,5,.,0,0,",,....and so on

nevermind! Now is working properly and show me all the data per user!

4

1 回答 1

0

我在users.php中更改了这部分代码

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

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

现在向我展示这些值的图表:

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

但是图表显示了每个分隔的数字和点......“,2,5,.,0,0,”,,......等等

没关系!现在工作正常并向我显示每个用户的所有数据!

于 2014-11-04T23:12:16.597 回答