我有個關聯的PHP陣列(field_data)和我想使用json_encode
功能把它傳遞給JS:$jArray = json_encode($field_data);
我recieving陣列中的JS:var irbrowser = <?php echo $jArray; ?>;
但在JS當我想設定jArray中餅圖數據的值,它不呈現任何東西。通行證數據作爲一個js變量highchart
<?php
$jArray = json_encode($field_data);
?>
<div dir="ltr" id="container"> </div>
<script>
var irbrowser = <?php echo $jArray; ?>;
$(function() {
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: 'Browser market shares'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
}
}
},
series: [{
name: "Brands",
colorByPoint: true,
data: [{
name: "IE",
y: irbrowser.IE
}, {
name: "Chrome",
y: irbrowser.Chrome,
sliced: true,
selected: true
}, {
name: "Proprietary or Undetectable",
y: irbrowser.Other
}]
}]
});
});
</script>
你可以試試firebug和console.log(irbrowser)嗎? – jezrael
我認爲你的json格式不正確,你可以過去嗎? – LTasty
irbrowser正在javascript中工作。因爲當我爲名稱(系列)設置irbrowser.IE時,它會在名稱標籤中顯示IE的正確值。 但yAxis它不起作用! –