dqroktbn005028 2014-08-31 20:36
浏览 41
已采纳

使用Json - PHP在谷歌聊天中设置列的样式

I am trying to use style "text-align: center" only on one column from the table (for example the slice's column in my code), but I only found how to add it in the Google Charts function. I didnt find anything showing how to do it with Ajax and Json.

I am calling the Google Charts in the Main.php.

And I am using Ajax to get the data from the Ajax.php file, using PHP and Arrays to create a Json.

Main.php

<html>
<head>
    <meta charset="utf-8">
   <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type='text/javascript' src='../../jquery-1.11.1.min.js'></script>
    <script type='text/javascript'>

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

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

   function drawChart() {
      //$('#chart_div').html("<img src='carregando.gif'>");
     var jsonData = $.ajax({
         url: "ajax.php",
         dataType:"json",
         async: false
         }).responseText;
     // Create our data table out of JSON data loaded from server.
     var data = new google.visualization.DataTable(jsonData);
     // Instantiate and draw our chart, passing in some options.
     var chart = new google.visualization.Table(document.getElementById('chart_div'));
     chart.draw(data, {width: 200});
   }

    </script>


</head>
<body>

<div id="chart_div"></div>

</body>
</html>

Ajax.php

<?php 

$table = array();
$table['cols'] = array(
    array('label' => 'Topping', 'type' => 'string'),
    array('label' => 'Slices', 'type' => 'number')

);

$rows = array();

$temp = array();
$temp[] = array('v' => 'Mushrooms');
$temp[] = array('v' => 3);
$rows[] = array('c' => $temp);

$temp = array();
$temp[] = array('v' => 'Onions');
$temp[] = array('v' => 1);
$rows[] = array('c' => $temp);

$table['rows'] = $rows;

$jsontable = json_encode($table);

echo $jsontable;

?>
  • 写回答

1条回答 默认 最新

  • dsztc99732 2014-09-01 15:22
    关注

    Add the style as a cell property to each cell you want to change:

    $temp = array();
    $temp[] = array('v' => 'Onions');
    $temp[] = array('v' => 1, 'p' => array('style' => 'text-align: center'));
    $rows[] = array('c' => $temp);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题