[英]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.