0

我正在尝试使用 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>
4

1 回答 1

2

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

于 2012-08-26T13:46:18.137 回答