我只需要添加這個簡單的PHP數組即可在X軸上顯示。它不想顯示我的內容,我不明白爲什麼。如何將PHP數組添加到Highcharts的JS數組中
<!DOCTYPE HTML>
<html>
<head>
<?php
$array = array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"type="text/javascript"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
js_array = new Array(<?php echo json_encode($array) ?>);
$('#container').highcharts({
title: {
text: 'Monthly Average Temperature',
x: -20 //center
},
subtitle: {
text: 'Source: WorldClimate.com',
x: -20
},
xAxis: {
categories: js_array
}
不會解決你的問題,但你應該使用'[]'而不是'new Array' - 後者創建一個不需要的對象包裝器 – sgroves
試試'js_array = JSON.parse('<?php echo json_encode($ array )?>');' – user1477388
我沒那麼幸運。我仍然得到一個空白的屏幕。 – Tabias