将多个列值合并到一个标签中chart.js

Combine multiple columns values to one label in chart.js

提问人:JFirdaus 提问时间:5/23/2022 更新时间:6/7/2022 访问量:255

问:

我的表(tb_ticket)是这样的:

technician_1 Technician_2
均线 均线
汤姆 均线
丽莎 汤姆
安娜 丽莎
汤姆 汤姆

我的问题是如何让它变成这样:

艾玛=3,汤姆=4,安娜=1,丽莎=2

我的查询


<script>
var ctx = document.getElementById("myChart").getContext('2d');
  var myChart = new Chart(ctx, {
         type: 'bar',
               data: {
                  labels: ["Ema", "Tom", "Ana", "Lisa"],
                  datasets: [{
                  label: 'Request by technician',
                  data: [  

                  <?php 
                  $technician_ema= mysqli_query($koneksi,"select * from tb_ticket where (technician_1','technician_2)='Ema'");
                  echo mysqli_num_rows($technician_ema);
                  ?>, 

                  <?php 
                  $technician_tom= mysqli_query($koneksi,"select * from tb_ticket where (technician_1','technician_2)='Tom'");
                  echo mysqli_num_rows($technician_tom);
                  ?>,

                  <?php 
                  $technician_ana= mysqli_query($koneksi,"select * from tb_ticket where (technician_1','technician_2)='Ana'");
                  echo mysqli_num_rows($technician_ana);
                  ?>, 
                  <?php 
                  $technician_lisa= mysqli_query($koneksi,"select * from tb_ticket where (technician_1','technician_2)='Lisa'");
                  echo mysqli_num_rows($technician_lisa);
                  ?>

                   ],
                   backgroundColor: [
                   '#1B4F72',
                   '#21618C',
                   '#2874A6',
                   '#2E86C1'
                    ],
                    }]
                    },
                   options: {
                       scales: {
                           xAxes: [{
                              ticks: {
                                autoSkip: false
                                }
                             }]
                            }
                           }
                        });
                 </script>

将第 technician_1 列和technicians_2的技术人员总数合并到条形图中。

我的图表是这样的

JavaScript PHP HTML MySQLI chart.js

评论


答:

0赞 JFirdaus 6/7/2022 #1

解决。 更改下面的代码。

<?php 
$technician_lisa= mysqli_query($koneksi,"select * from tb_ticket where technician_1='lisa' or technician_2='Lisa'");
echo mysqli_num_rows($technician_lisa);
?>