从 php 解析数据到 jsquery.flot.pie
我已经看到了一些关于此的问题,但我仍然无法清除周围的迷雾...
我有这个 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 技术交流群。

最可能的问题是您的数字数据被解释为字符串。
来自 API.txt:
因此,要么在 PHP 端强制数据为数字类型,要么在 javascript 中执行,也许使用 .
Number(some_data)
The most likely problem is that your numeric data is being interpreted as a string.
From the API.txt:
So either force your data to numeric types on the PHP side, or do it in javascript, perhaps with .
Number(some_data)