Google Charts添加第二个查询(第二行)

时间:2017-02-28 13:11:26

标签: php mysql charts linechart

首先,我制作的图表正在运行,但现在我需要更改1件事,然后每个人都很开心。我创建了一个带有1个查询的图表,它看起来像这样: enter image description here

现在我需要在此线图中使用第二个查询添加另一行

例如,像这样的东西(来自谷歌的例子不是我的!)enter image description here

我取得了一些进展并做到了这一点。是的,我仍然怀念第二个查询的一个小东西,所有的行是相同的。这不是计划或目的。第二行(查询)仅显示查询的第一个结果

第一个查询很好,它可以完成我想要的但不是第二个查询。

像这样一个: enter image description here

这是新脚本:

    <!--Load the AJAX API-->
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  <script type="text/javascript">

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

  google.setOnLoadCallback(drawChart);

  function drawChart() {

        var data = google.visualization.arrayToDataTable([

          ['Weekly TotalExcl', 'Previous', 'Current'],

        <?php 

            $query = "SELECT COUNT(o.id_customer) AS Orders, SUM(o.total_paid_tax_excl) AS TotalExcl, AVG(o.total_paid_tax_excl) AS Average, IFNULL(CONCAT(c.company), 'W') AS Customer FROM ex.ps_orders o LEFT JOIN ex.ps_customer c ON o.id_customer = c.id_customer WHERE YEAR(o.date_add) = YEAR(UTC_TIMESTAMP()) GROUP BY c.company ORDER BY TotalExcl DESC limit 10";

            $exec = mysqli_query($con,$query);
            while($row = mysqli_fetch_array($exec)){

              echo "['".$row['Customer']."',";

              $query2 = "SELECT COUNT(o.id_customer) AS Orders, SUM(o.total_paid_tax_excl) AS TotalExcl, AVG(o.total_paid_tax_excl) AS Average, IFNULL(CONCAT(c.company), 'W') AS Customer FROM ex.ps_orders o LEFT JOIN ex.ps_customer c ON o.id_customer = c.id_customer WHERE YEAR(o.date_add) = YEAR(UTC_TIMESTAMP()) GROUP BY c.company ORDER BY TotalExcl DESC limit 10";

              $exec2 = mysqli_query($con,$query2);
              $row2 = mysqli_fetch_assoc($exec2);

              echo $row2['Average'];

              $rvisits = $row['TotalExcl']-$row2['Customer'];

              echo ",".$rvisits."],";
            }
     ?>
        ]);

        var options = {
          legend: {position: 'top', maxLines: 2},
          hAxis: {minValue: 0},
          bars: 'vertical',
          colors: ['#4682B4','#FF4500'],
          animation: { "startup": true, duration: 2000, easing: 'in' },
          allowHtml: true,
        };

        var material  = new google.visualization.BarChart(document.getElementById('barchart17'));
        material .draw(data, google.charts.Bar.convertOptions(options));
      }

    </script>

0 个答案:

没有答案