[英]google chart with php loop in data array not displaying
我正在尝试在谷歌图表中显示一些 PHP 代码。 我在同一页面上有另一个图表使用相同的过程,并且工作正常,但由于某种原因,第二个图表没有显示。
我在 PHP 中有一个键值数组,我知道它包含我需要的信息,因为我已经用这个循环对其进行了测试。
foreach($categoryKeyValues as $key => $value){
echo "['".$key.' '.$_SESSION['currency'].number_format($value,2)."',
".number_format($value,2)."],";
}
并且它显示正确,因此数据就在那里。
这是循环中的 output ['Entertainment £167.99', 167.99],['Other £0.00', 0.00],['Bill £1,155.81', 1,155.81],['Motoring £225.00', 225.00],[ £126.58', 126.58],['节省 £187.00', 187.00],['场合 £87.50', 87.50],['保险 £37.00', 37.00],
当我调用 javascript 显示图表时出现错误,图表不显示。 这是我的图表代码。
<!-- Graph for Categorised expenditure -->
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawCategory);
function drawCategory()
{
var data = google.visualization.arrayToDataTable([
['Category', 'Total'],
<?php
foreach($categoryKeyValues as $key => $value)
{
if($value > 0){
echo "['".$key.' '.$_SESSION['currency'].number_format($value,2)."', ".number_format($value,2)."],";
$atotal = $atotal + $value;
}
}
//$title = "Account Type, Total - ".$total;
?>
]);
var options = {
is3D:true,
chartArea: {left: '1%', top: '5%', right:'1%', width: '95%', height: '100%'},
width: $(window).width()*0.50,
height: $(window).width()*0.20,
pieSliceText: 'none',
sliceVisibilityThreshold: 0.00,
pieHole:0.4,
tooltip: {
isHtml:true,
showColorCode: true,
trigger: 'hover'
},
colors: ['#204969', '#719192', '#5f6769', '#5c94bd','#1a3e59', '#315b96', '#719192', '#3c4245', '#dadada']
};
var chart = new google.visualization.PieChart(document.getElementById('categoryChart'));
chart.draw(data, options);
}
// And then:
$(window).resize(function () {
drawCategory();
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.