多个google图表和多个sql查询

ia2d9nvy  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(221)

我对发展世界还很陌生。我试图创建一个 Jmeter 板使用谷歌图表。我正在使用sql查询来实现这一点,我已经成功地按照一个示例创建了一个运行良好的图表,但是现在我必须以类似的方式创建多个图表。谷歌图表显示了如何做到这一点,但它不是使用sql查询,我需要使用mysql查询的数据,所以请有人可以帮助我如何做到这一点,我真的很感激。
非常感谢!
代码如下:

<?php
$connect = mysqli_connect("localhost", "root", "", "test");
$query = "SELECT 'Health Members' AS 'Member Type', COUNT(policy_no) AS 'Total'
FROM health
WHERE health.`status` > 600
UNION
SELECT 'Health Spouses' AS 'Member Type', COUNT(policy) AS 'Total'
FROM health_dependents
WHERE active = 1
AND dc <> 99
AND dc = 01
UNION
SELECT 'Health Dependents' AS 'Member Type', COUNT(policy) AS 'Total'
FROM health_dependents
WHERE active = 1
AND dc <> 99
AND dc <> 01
AND dc <> 00
UNION
SELECT 'Dental Members' AS 'Member Type', COUNT(policy_no) AS 'Total'
FROM dental
WHERE dental.`status` > 600
UNION
SELECT 'Dental Spouses' AS 'Member Type', COUNT(policy) AS 'Total'
FROM dental_dependents
WHERE active = 1
AND dc <> 99
AND dc = 01
UNION
SELECT 'Dental Dependents' AS 'Member Type', COUNT(policy) AS 'Total'
FROM dental_dependents
WHERE active = 1
AND dc <> 99
AND dc <> 01
AND dc <> 00
UNION
SELECT 'Rescue Members' AS 'Member Type', COUNT(policy_no) AS 'Total'
FROM rescue
WHERE rescue.`status` > 600
UNION
SELECT 'Rescue Spouses' AS 'Member Type', COUNT(policy) AS 'Total'
FROM rescue_dependents
WHERE active = 1
AND dc <> 99
AND dc = 01
UNION
SELECT 'Rescue Dependents' AS 'Member Type', COUNT(policy) AS 'Total'
FROM rescue_dependents
WHERE active = 1
AND dc <> 99
AND dc <> 01
AND dc <> 00
UNION
SELECT 'Umsizilife Members' AS 'Member Type', COUNT(policy_no) AS 'Total'
FROM umsizilife
WHERE umsizilife.`status` > 600
UNION
SELECT 'Umsizilife Spouses' AS 'Member Type', COUNT(policy) AS 'Total'
FROM umsizilife_dependents
WHERE active = 1
AND dc <> 99
AND dc = 01
UNION
SELECT 'Umsizilife Dependents' AS 'Member Type', COUNT(policy) AS 'Total'
FROM umsizilife_dependents
WHERE active = 1
AND dc <> 99
AND dc <> 01
AND dc <> 00";  
$result = mysqli_query($connect , $query);  
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Active Members Dashboard</title>

    <!-- Bootstrap -->
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <!-- Styles -->
    <link href="_css/styles.css" rel="stylesheet">
    <!-- date picker -->
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <!-- data tables -->
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap.min.css">
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

<div class="container">
    <div class="page-content">
    <!-- inside wrapper -->

        <!-- page header -->
        <?php require_once("/elements/top.php") ?>

        <!-- BUILD PAGE HERE -->
        <table class="columns">
            <tr>
                <td><div id="AllProducts" style="width: 800px; height: 400px;"></div></td>
                <td><div></div></td>
            </tr>
        </table> 

    </div>
</div>  

</body>

    <!-- inside wrapper -->

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="bootstrap/js/bootstrap.min.js"></script>    
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <!-- data tables -->
    <script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap.min.js"></script>

    <script type="text/javascript">  
        google.charts.load('current', {'packages':['corechart']});  
        google.charts.setOnLoadCallback(drawChart);  
        function drawChart()  
           {  
                var data = google.visualization.arrayToDataTable([  
                          ['Member Type', 'Total'],  
                          <?php  
                          while($row = mysqli_fetch_array($result))  
                          {  
                               echo "['".$row["Member Type"]."', ".$row["Total"]."],";  
                          }  
                          ?>  
                     ]);  
                var options = {  
                      pieHole: 0.4,
                      chartArea:{left:0,top:50,width:"800%",height:"400%"} 
                     };  
                var chart = new google.visualization.PieChart(document.getElementById('AllProducts'));  
                chart.draw(data, options);  
           }  
    </script> 
</html>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题