开发者

Parse data from php to jsquery.flot.pie

I've seen some questions about this already but I still couldn't clear the fog around this...

I have this sql statement to get data:

<script type="text/javascript">


<?php

$query = "SELECT rel_id, SUM(suma) FROM $tbl_rel_balansas INNER JOIN $tbl_balansas ON $tbl_rel_balansas.rel_id = $tbl_balansas.id WHERE $tbl_rel_balansas.member_id = '$_SESSION[id]'";
$result = mysql_query ($query);
while($row = mysql_fetch_array($result)){
    echo 'var some_data = ' . json_encode( $viso );
}


?>
开发者_JS百科

Next is the js part:

    $(function () {


   $.plot($("#placeholder"), [some_data], 
{
        series: {
            pie: { 
                show: true
            }
        },
        legend: {
            show: false
        }
});
});
</script> 

I was thinking I could reach the data in some_data and use it to display it in the pie chart, unfortunately this is not the way to go.

Any help and suggestions are greatly appriciated ! :)


The most likely problem is that your numeric data is being interpreted as a string.

From the API.txt:

Note that to simplify the internal logic in Flot both the x and y values must be numbers (even if specifying time series, see below for how to do this). This is a common problem because you might retrieve data from the database and serialize them directly to JSON without noticing the wrong type. If you're getting mysterious errors, double check that you're inputting numbers and not strings.

So either force your data to numeric types on the PHP side, or do it in javascript, perhaps with .Number(some_data)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜