简体   繁体   English

如何为数据库查询返回给我的每一行制作饼图?

[英]How can I make a piechart chart for each row that the database query returns to me?

I have 2 or more columns and I have to perform calculation using all columns.我有 2 列或更多列,我必须使用所有列执行计算。 And for each row I have to show Pie chart next to that.对于每一行,我必须在旁边显示饼图。 Creating Pie -chart for suppose 10 rows based on if-else calculation.根据 if-else 计算为假设 10 行创建饼图。 If anyone can help.如果有人可以提供帮助。 Thanks.谢谢。 I'm work in php.我在 php 工作。

I already made a pie chart as shown in the code below, but I don't know how to create them dynamically.我已经制作了如下代码所示的饼图,但我不知道如何动态创建它们。

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
                  google.charts.load('current', {'packages':['corechart']});
                  google.charts.setOnLoadCallback(drawChart);

                  function drawChart() {

                    var data = google.visualization.arrayToDataTable([
                      ['Total de Horas', '8 horas'],
                      <?php foreach ($list as $l) :?>
                      ['Horas faturadas',     <?php echo $l->HorasFaturadas; ?>],
                      ['Horas não faturadas',       <?php echo $l->NaoFaturadas; ?>],
                       <?php endforeach; ?>
                      ['Hours break',120]
                    ]);

                    var options = {
                      title: 'Daily Activities ',
                      slices: {
                        0: { color: 'green' },
                        1: { color: 'red' },
                        2: { color: 'grey'}
                      }
                    };

                    var chart = new 
  google.visualization.PieChart(document.getElementById('piechart'));

                    chart.draw(data, options);
                  }
                </script>  '''

I think you need to clarify more about the dynamic part, if you want data to be shown in real time you will need something like AJAX.我认为您需要进一步澄清动态部分,如果您希望实时显示数据,您将需要 AJAX 之类的东西。 AJAX would send data to the controller, the controller to the model, and if the action has success then it will change the data in real time or in a dynamic way. AJAX would send data to the controller, the controller to the model, and if the action has success then it will change the data in real time or in a dynamic way.

as for the charts, I would use the popular library charts.js至于图表,我会使用流行的库charts.js

So, every value that you will calculate with the if-else statements, you will store them in a variable and then show that variable value on the chart.因此,您将使用 if-else 语句计算的每个值,您将它们存储在一个变量中,然后在图表上显示该变量值。 Here is an answer that might help you.这是一个可能对您有所帮助的答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何对数据库中的每一行应用数学mysql查询? - How do I apply a mathematical mysql query to each row in a database? 如何在MYSQL中查询每年的每个月? - How can I make a query for each month of each year in MYSQL? 如何为表格中的每一行制作一个接受按钮? - How can I make an accept button for each row in the table? 我怎样才能为每个记录运行一个SQL查询 - How can i make a sql query to run for each record 仅当选择查询返回一行时,才如何更新一行? - How can I update a row only if a select query returns one row? 如何安排此代码,以便可以从数据库中为每个表行获取不同的条目 - How can I arrange this code so I can get different entry from database for each table row 如何解决显示每种产品四次而不是一次的查询? - How can i fix my query that shows me four times each of the products instead of one? 如何使用array_push在PHP / Laravel中通过数据库查询结果在foreach循环中添加键值对以标记返回的每一行? - How can I use array_push to add a key value pair in a foreach loop through database query results in PHP/Laravel to flag each row returned? 在 OrderBy desc Eloquent 查询中获取行的排名,我怎样才能使这个查询在 laravel 5.5 eloquents 中工作?) - Getting rank of row in OrderBy desc Eloquent query, How can i make this query work in laravel 5.5 eloquents?) 我该如何进行此查询? - How can I make this query?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM