从 php 解析数据到 jsquery.flot.pie

发布于 10-31 00:40 字数 821 浏览 3 评论 0原文

我已经看到了一些关于此的问题,但我仍然无法清除周围的迷雾...

我有这个 sql 语句来获取数据:

<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 部分:

    $(function () {


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

我想我可以访问 some_data 中的数据并使用它将其显示在饼图中,不幸的是这不是正确的方法。

非常感谢任何帮助和建议! :)

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 );
}


?>

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 ! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坠似风落2024-11-07 00:40:47

最可能的问题是您的数字数据被解释为字符串。

来自 API.txt

请注意,为了简化内部
Flot 中的逻辑 x 和 y 值
必须是数字(即使指定
时间序列,请参阅下面的操作方法
这)。这是一个常见问题
因为您可能会从中检索数据
数据库并序列化它们
直接转换成 JSON 而不注意
类型错误。如果你得到
神秘错误,请仔细检查
你正在输入数字而不是
字符串。

因此,要么在 PHP 端强制数据为数字类型,要么在 javascript 中执行,也许使用 .Number(some_data)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文