[英]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.