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 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算