如何将PHP数组添加到Highcharts中的JS数组 [英] How to add PHP array to JS array in Highcharts
本文介绍了如何将PHP数组添加到Highcharts中的JS数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<!DOCTYPE HTML>
< html>
< head>
$ php
$ array = array(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug九月, 月, 月, 月);
?>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8>
< title> Highcharts示例< / title>
< script src =// ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js\"type=\"text/javascript\"> ;</script>
< script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js>< / script>
< script type =text / javascript>
$ b $(函数(){
js_array = new Array(<?php echo json_encode($ array)?>);
$('# (
标题:{
text:'Monthly Average Temperature',
x:-20 // center
},
subtitle:{
text:'Source:WorldClimate.com',
x:-20
},
xAxis:{
类别:js_array
}
解决方案
我们似乎在这里过于复杂......
改变这个:
js_array = new Array(<?php echo json_encode($ array )?>);
...
xAxis:{
类别:js_array
}
对此:
xAxis:{
类别:<?php echo jso n_encode($ array);?>
}
All I want is to be able to add this simple PHP array to display in the X axis. It's not wanting to display my content at all and I'm not understanding why.
<!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 }
解决方案We seem to be overcomplicating matters here...
change this:
js_array = new Array(<?php echo json_encode($array) ?>); ... xAxis: { categories: js_array }
to this:
xAxis: { categories: <?php echo json_encode($array); ?> }
这篇关于如何将PHP数组添加到Highcharts中的JS数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文