google.visualization.DataTable(<! - ?php $ jdata? - >)?

时间:2012-08-26 13:43:06

标签: php google-visualization

我正在尝试使用Google可视化和php / mysql生成图表。 我的数据如下:

      ['RTI', 3],
      ['USAID', 1],
      ['Task Force', 1],
      ['DFID', 1],
      ['Other', 2]

如果我打印$ jdata我得到:

[{"Response":"Other","Count":"3"},{"Response":"RTI","Count":"3"},{"Response":"USAID","Count":"4"}]

看起来非常接近。有什么建议吗?

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">

  // Load the Visualization API and the piechart package.
  google.load('visualization', '1.0', {'packages':['corechart']});

  // Set a callback to run when the Google Visualization API is loaded.
  google.setOnLoadCallback(drawChart);

  // Callback that creates and populates a data table,
  // instantiates the pie chart, passes in the data and
  // draws it.
  function drawChart() {
  
    // Create the data table.
    var data = new google.visualization.DataTable(<?php $jdata ?>);

    // Set chart options
    var options = {'title':"Question1: I'm here to represent:",
                   'width':400,
                   'height':300};

    // Instantiate and draw our chart, passing in some options.
    var chart = new google.visualization.PieChart(document.getElementById('chart_div1'));
    chart.draw(data, options);
  }
</script>

1 个答案:

答案 0 :(得分:2)

<?php $jdata ?>什么都不做 - 你需要回应它 - <?php echo $jdata ?>