dragon5006 2013-10-21 16:35
浏览 45

将Google图表放置在特定位置

Thanks for all the inputs from Stackoverflow. I am able to place the 2 google chart in one page, but the 2nd chart is showing below 1st chart. But i need both charts in parallel to each other. Like: 1st chart from Left it should be 100th position, top =200 and 2nd chart should be 300th position, top=200. How can i achieve that. I used chartArea:{left:20,top:0,width:"50%",height:"75%"}, but i am not getting

<?php
$con=mysql_connect("","root","") or die("Failed to connect with database!!!!");
mysql_select_db("Loan_Bids", $con); 

$sth = mysql_query("SELECT A.Bid_Size, B.Rating from bids_data A, loan_data B Where A.LoanID = B.LoanID");


$rows = array();
$rows1 = array();

//flag is not needed
$flag = true;
$table = array();

$table['cols'] = array(

    array('label' => 'Bid_Size', 'type' => 'number'),
    array('label' => 'Rating', 'type' => 'number')
);

$table1 = array();

$table1['cols'] = array(

    array('label' => 'Bid_Size', 'type' => 'number'),
    array('label' => 'Rating', 'type' => 'number')
);

$rows = array();
$rows1 = array();

while($r = mysql_fetch_assoc($sth)) {

    $Ratingval = $r['Rating'];
    if ($Ratingval == 1 ) 
    {
       $temp = array();
    // the following line will be used to slice the Pie chart
       $temp[] = array('v' => (int) $r['Bid_Size']); 
    // Values of each slice
       $temp[] = array('v' => (int) $r['Rating']); 
      $rows[] = array('c' => $temp);
    }
    if ($Ratingval == 2 ) 
    {
       $temp1 = array();
     // the following line will be used to slice the Pie chart
       $temp1[] = array('v' => (int) $r['Bid_Size']); 
    // Values of each slice
       $temp1[] = array('v' => (int) $r['Rating']); 
      $rows1[] = array('c' => $temp1);
    }

}

$table['rows'] = $rows;
$jsonTable = json_encode($table);

$table1['rows'] = $rows1;
$jsonTable1 = json_encode($table1);
echo $jsonTable1;

?>

 <html>
  <head>
    <!--Load the Ajax API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script type="text/javascript">

    google.load('visualization', '1', {'packages':['corechart']});

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

    function drawChart() {

      // Create our data table out of JSON data loaded from server.
      var data = new google.visualization.DataTable(<?php echo $jsonTable?>);
      var options = {
           title: 'Rating1',
          is3D: 'true',
          color:'red',
          hAxis: {title: 'Interest Rate'},
          vAxis: {title: 'Bid Size'},
          width:200,height:200
   };

       var data1 = new google.visualization.DataTable(<?php echo $jsonTable1?>);
      var options1 = {
           title: 'Rating2',
          is3D: 'true',
          hAxis: {title: 'Interest Rate'},
          vAxis: {title: 'Bid Size'},
          width:200,height:200
          };
      // Instantiate and draw our chart, passing in some options.
      // Do not forget to check your div ID
      var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));
      chart.draw(data, options);

      var chart1 = new google.visualization.ScatterChart(document.getElementById('chart_div1'));
      chart1.draw(data1, options1);

 }
    </script>
  </head>

  <body>
    <!--this is the div that will hold the pie chart-->
    <div id="chart_div"></div>
    <div id="chart_div1"></div>
  </body>
</html>
  • 写回答

1条回答 默认 最新

  • douyong5825 2013-10-21 17:22
    关注

    You need to use CSS to position the container divs on the page, not the chartArea options. Something like this should work:

    #chart_div, #chart_div1 {
        float: left;
        width: 50%;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥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 可否在不同线程中调用封装数据库操作的类