Advertisement
bru_ce

dúvida php

Jul 23rd, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. /*HTML*/
  2. <!doctype html>
  3. <html>
  4. <head>
  5.     <title>Bar Chart</title>
  6.     <script src="Chart.js-master/Chart.js"></script>
  7. </head>
  8. <body>
  9. <div style="width: 50%">
  10.     <canvas id="pergunta1" height="450" width="600"></canvas>
  11. </div>
  12.  
  13.  
  14. <script>
  15.     var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
  16.  
  17.  
  18.  
  19.  
  20.  
  21.     var barChartData = {
  22.         labels : ["0","1","2","3","4","5"],
  23.         datasets : [
  24.             {
  25.  
  26.                 label: "Dados primários",
  27.                 fillColor: "rgba(220,220,220,0.2)",
  28.                 strokeColor: "rgba(220,220,220,1)",
  29.                 pointColor: "rgba(220,220,220,1)",
  30.                 pointStrokeColor: "#fff",
  31.                 pointHighlightFill: "#fff",
  32.                 pointHighlightStroke: "rgba(220,220,220,1)",
  33.                 <?php
  34.                 include('query.php');
  35.  
  36.                 ?>
  37.  
  38.             }
  39.         ]
  40.  
  41.     }
  42.     window.onload = function(){
  43.         var ctx = document.getElementById("pergunta1").getContext("2d");
  44.         window.myBar = new Chart(ctx).Bar(barChartData, {
  45.             responsive : true
  46.         });
  47.     }
  48.  
  49. </script>
  50.  
  51.  
  52. </body>
  53. </html>
  54.  
  55.  
  56. /*CONSULTA*/
  57. <?php
  58. $total = mysql_query("SELECT * FROM tabela WHERE statusPesquisa=2");
  59. $linhaTotal = mysql_num_rows($total);
  60.  
  61.  
  62.  
  63. $inicio = 0;
  64.  
  65. echo "data : [";
  66. while($inicio <= 5){
  67.  
  68.     $query = "&#36query$inicio";
  69.     $row = "&#36row$inicio";
  70.     $notapergunta = "notapergunta$inicio";
  71.  
  72.  
  73.  
  74.     $query = mysql_query("SELECT * FROM tabela WHERE notapergunta1=$inicio AND statusPesquisa=2");
  75.     $row  = mysql_num_rows($query);
  76.  
  77.     if($inicio == 0) {
  78.         $percent = 0;
  79.     } else{
  80.         $percent = 359 / $row;
  81.     }
  82.  
  83.  
  84.     if($inicio != 5) {
  85.         echo round($percent).",";
  86.     }
  87.     else {
  88.         echo round($percent);
  89.     }
  90.  
  91.  
  92.  
  93.     $inicio++;
  94. }
  95. echo "]";
  96.  
  97.  
  98.  
  99.  
  100. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement