使用Google图表生成包含静态数据的图形

用户名

我想为我的静态数据生成图形。我正在使用Google Chart执行此操作。这是谷歌图表代码

<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     11],
          ['Eat',      2],
          ['Commute',  2],
          ['Watch TV', 2],
          ['Sleep',    7]
        ]);

        var options = {
          title: 'My Daily Activities'
        };

        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="chart_div" style="width: 900px; height: 500px;"></div>
  </body>
</html>

但是我想把我的代码放在这里。我没有怎么做。这是我的代码

<?php
echo '<div align="center" style="width:100%; padding-top:20px;">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
      <tr>
        <td class=tddash>10 latest purchase orders</td>
      </tr>
      <tr>
        <td>';
        $SQL = 'SELECT purchorders.orderno,
                        suppliers.suppname,
                        purchorders.orddate,
                        purchorders.deliverydate,
                        purchorders.initiator,
                        purchorders.requisitionno,
                        purchorders.allowprint,
                        purchorders.status,
                        suppliers.currcode,
                        currencies.decimalplaces AS currdecimalplaces,
                        SUM(purchorderdetails.unitprice*purchorderdetails.quantityord) AS ordervalue
                    FROM purchorders 
                    INNER JOIN purchorderdetails 
                    ON purchorders.orderno = purchorderdetails.orderno
                    INNER JOIN suppliers
                    ON purchorders.supplierno = suppliers.supplierid
                    INNER JOIN currencies 
                    ON suppliers.currcode=currencies.currabrev
                    WHERE purchorders.orderno=purchorderdetails.orderno
                    GROUP BY purchorders.orderno,
                        suppliers.suppname,
                        purchorders.orddate,
                        purchorders.initiator,
                        purchorders.requisitionno,
                        purchorders.allowprint,
                        purchorders.status,
                        suppliers.currcode,
                        currencies.decimalplaces LIMIT 5';
                        $SalesOrdersResult2 = DB_query($SQL,$db);
                        $Total = 0;
                echo '<table width="100%" celpadding="2" class="selection">';
                        echo '<tbody><tr><th> Supplier </th><th>Order Date</th><th>Delivery Date</th><th>Initiator</th><th>Order Total</th><th>Status</th></tr></tbody> ';
                        $k=0;
                while ($row = DB_fetch_array($SalesOrdersResult2))
                    //while ($row = mysql_fetch_array($SalesOrdersResult))
                    {
                        if ($k == 1){
            echo '<tr class="EvenTableRows">';
            $k = 0;
        } else {
            echo '<tr class="OddTableRows">';
            $k = 1;
        }
                        $FormatedOrderValue2 = locale_number_format($row['ordervalue'],$row['currdecimalplaces']);
                        $Total += $row['ordervalue'];
                        //$FormatedOrderValue1 = locale_number_format($myrow['ordervalue'],$_SESSION['CompanyRecord']['decimalplaces']);
                        $FormatedOrderDate1 = ConvertSQLDate($row['orddate']);
                        $FormatedDelDate1 = ConvertSQLDate($row['deliverydate']);

                        echo ' <td> ' . $row['suppname'] . ' </td>';
                        echo ' <td>$FormatedOrderDate1</td><td>$FormatedDelDate1</td><td> ' . $row['initiator'] . ' </td><td>$FormatedOrderValue2</td><td> ' . $row['status'] . ' </td> ';

                    }
        echo '<tr><td colspan="3">Total---</td><td colspan="2">$Total</td></tr></tbody>';           
        echo '</table></td>';


     echo' </tr>
    </table>

</div>';

有人可以帮我吗?

*编辑*

echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>';
   echo ' <script type="text/javascript">


      function drawChart() {
        var jsonData = $.ajax({
          url: "1getData.php",
          dataType:"json",
          async: false
          }).responseText;

          alert(jsonData);



       var data = new google.visualization.DataTable(jsonData);
         var view = new google.visualization.DataView(data);
         view.setColumns([0, 3]);
         var chart = new google.visualization.ColumnChart(document.getElementById("chart_div"));
      chart.draw(view, {width:400, height:240});
      }
 google.load("visualization", "1", {packages:["corechart"]});
  google.setOnLoadCallback(drawChart);

</script>';
echo '</head>'; 
<div id="chart_div" ></div>

1getData.php

<?php

$PageSecurity=0;
include('includes/session.inc');
if (!isset($RootPath)){
        $RootPath = dirname(htmlspecialchars($_SERVER['PHP_SELF']));
        if ($RootPath == '/' or $RootPath == "\\") {
            $RootPath = '';
        }
    }

    $SQL = "SELECT workorders.wo, woitems.stockid, stockmaster.description, stockmaster.decimalplaces, woitems.qtyreqd, woitems.qtyrecd, workorders.requiredby, workorders.startdate
FROM workorders
INNER JOIN woitems ON workorders.wo = woitems.wo
INNER JOIN stockmaster ON woitems.stockid = stockmaster.stockid
ORDER BY workorders.wo";
                    $searchresult = DB_query($SQL, $db);
                    $table=array();

                    $table['cols']=array(
                    array('label'=>'ITEM', type=>'string'),
                    array('label'=>'Description', type=>'string'),
        array('label'=> 'QTY Required', type=>'number'),
        array('label'=>'QTY Outstanding', type=>'number')

);
$rows=array();


                    while ($row = DB_fetch_array($searchresult))
                    {

            $qreq = locale_number_format($row['qtyreqd'],$row['decimalplaces']);
            $qout = locale_number_format($row['qtyreqd']-$row['qtyrecd'],$row['decimalplaces']);


                        $temp=array();

        $temp[]=array('v' => $row['stockid']);
        $temp[]=array('v' => $row['description']);
        $temp[]=array('v' => $row['qtyreqd']);

        $temp[]=array('v' => ($row['qtyreqd']-$row['qtyrecd']));

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


                    }
                    $table['rows']=$rows;

$jsonTable = json_encode($table);
print $jsonTable;




?>

但它只显示两列,我想在其中显示3


Java脚本

<script type="text/javascript">


      function drawChart() {
        var jsonData = $.ajax({
          url: "1getData.php",
          dataType:"json",
          async: false
          }).responseText;

          alert(jsonData);



       var data = new google.visualization.DataTable(jsonData);
         var view = new google.visualization.DataView(data);
         view.setColumns([0,3]);

         var chart = new google.visualization.ColumnChart(document.getElementById("chart_div"));
      chart.draw(view, {width:400, height:240});

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

    </script>
杰里米·法尔(Jeremy Faller)

您的行view.setColumns([0, 3])告诉Google图表仅显示数据中的第一列和第四列。将要显示的列添加到数组。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在 bookdown 生成的 epub 中包含图形/绘图/图表?

来自分类Dev

如何使用Google图表获取实时图形?

来自分类Dev

如何根据用户输入使用现代UI图表生成图形

来自分类Dev

如何根据用户输入使用现代UI图表生成图形

来自分类Dev

无法使用MySQL表数据作为数据源来生成Google图表

来自分类Dev

使用Peewee ORM生成图形数据

来自分类Dev

使用Peewee ORM生成图形数据

来自分类Dev

使用Peewee ORM生成图形数据

来自分类Dev

使用SharePoint列表数据的Google图表

来自分类Dev

使用knitr和rgl在html中包含3D交互式图形,在word / pdf中包含静态图形

来自分类Dev

从动态生成的数据设置Google图表多轴

来自分类Dev

如何从C#生成图形和图表

来自分类Dev

使用 2 个数据集生成图表 Charts.js

来自分类Dev

使用SQL生成包含稀疏数据的列?

来自分类Dev

使用多个Google图表和jspdf生成PDF

来自分类Dev

使用数据存储区数据渲染Google图表

来自分类Dev

使用数据存储区数据渲染Google图表

来自分类Dev

使用数据库数据在Google图表上显示报告

来自分类Dev

Google图表输入数据

来自分类Dev

使用具有多个数据数组的图表创建图形

来自分类Dev

如何使用Google图表在同一图形上绘制散点图和折线图

来自分类Dev

如何使用JSON中的动态数据使用Google图表

来自分类Dev

图表或图形

来自分类Dev

Google图表-表格图表不显示数据

来自分类Dev

使用Django将数据传递到Google图表

来自分类Dev

使用按钮更改Google图表数据和外观

来自分类Dev

使用计算总和作为Google图表的数据

来自分类Dev

使用json数据时Google图表为空

来自分类Dev

使用PHP从SQL Server数据库获取Google图表

Related 相关文章

热门标签

归档