douyasihefu6214 2013-07-18 05:45
浏览 96
已采纳

从php发送数组到jquery

how do i pass an array from php to jquery both are in same file , i just have an array named $array2 with data that will be used to make graph below code is using chartdata but i want to use variable from my php script

 <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
var chart;

var chartData = [{
    student: 5,
    marks: 0},
{
    student: 8,
    marks: 50},
{
    student: 10,
    marks: 100}];


AmCharts.ready(function() {
    // SERIAL CHART
    chart = new AmCharts.AmSerialChart();
    chart.dataProvider = chartData;
    chart.categoryField = "marks";
    chart.startDuration = 1;

    // AXES
    // category
    var categoryAxis = chart.categoryAxis;
    categoryAxis.labelRotation = 90;
    categoryAxis.gridPosition = "student";

    // value
    // in case you don't want to change default settings of value axis,
    // you don't need to create it, as one value axis is created automatically.
    // GRAPH
    var graph = new AmCharts.AmGraph();
    graph.valueField = "student";
    graph.balloonText = "[[category]]: [[value]]";
    graph.type = "column";

    graph.lineAlpha = 0;
    graph.fillAlphas = 8.4;
    chart.addGraph(graph);

    chart.write("chartdiv");
});
 </script>
  • 写回答

4条回答 默认 最新

  • duanpacan9388 2013-07-18 05:57
    关注

    you can use json data to pass php to jquery.

    in php

    $php_data = json_encode($your_php_data_in_array);
    

    assigning to jquery

    var data = <?php echo $php_data ;?>
    

    getting the value in jquery

    var chart_data_arr = json_decode(data);
    

    now you have the data in array in jquery.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办