我正在研究一個將顯示條形圖的項目。條形圖工作正常,但是當我嘗試將一個整數php變量傳遞給javascript變量並添加變量作爲列表元素不起作用時。下面是我的代碼。我不知道我的源代碼有什麼問題。我花了幾個小時在網上尋找解決方案,但我沒有得到任何答案。如何將php變量作爲javascript中的列表元素
期待看到您的回覆。
<html>
<head><title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<style type="text/css">
#container {
height: 400px;
min-width: 310px;
max-width: 800px;
margin: 0 auto;
}
</style>
<?php
//my php variable
$ab=6;
?>
<script type="text/javascript">
//assign the php variable to javascript variable
var za = <?php echo $ab; ?>;
$(function() {
$('#container').highcharts({
chart: {
type: 'column',
options3d: {
enabled: true,
alpha: 10,
beta: 25,
depth: 70
}
},
title: {
text: '3D chart with null values'
},
subtitle: {
text: 'Notice the difference between a 0 value and a null point'
},
plotOptions: {
column: {
depth: 25
}
},
xAxis: {
categories: Highcharts.getOptions().lang.shortMonths
},
yAxis: {
title: {
text: null
}
},
series: [{
name: 'Sales',
// I'm putting the variable as an element below, but it's not working
data: [za, 3, null, 4, 0, 5, 1, 4, 6, 3]
}]
});
});
</script>
</head>
<body>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-3d.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="height: 400px"></div>
</body>
看起來它應該工作得很好。你有沒有檢查PHP的*輸出*是什麼? – Quentin
假設文件保存爲php並執行爲php它應該工作。如果你只是將它保存爲.html然後不是 – mplungjan
如果我在瀏覽器中訪問頁面時只是看到空白頁面(即沒有任何內容的頁面),但是如果用數字條形圖替換數據列表中的'za'變量顯示在頁面 – dyahmed