close

隨機亂數產生圓餅圖

<html>
  <head>
    <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);
      var a ;
      var b ;
      var c ;
      var d ;

var n1;var n2 ; var n3 ; var n4;
function random(){
var maxNum = 10;  
var minNum = 0;  
  n1 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum; 
  n2 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum; 
  n3 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum; 
  n4 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum; 
drawChart() ;
}

 function check1() {
      a = 0 ;
      b = 0 ;
      c = 0 ;
     d = 0 ;
       var radio1=document.getElementsByName("v1");
       var radio2=document.getElementsByName("v2");
       var radio3=document.getElementsByName("v3");
      var radio4=document.getElementsByName("v4");
          for(var i=0;i<radio1.length;i++)
   {if(radio1.item(i).checked==true)
             {flag1=i+1;
                if(i==0){a=a+1;}
                if(i==1){b=b+1;}
                if(i==2){c=c+1;}
                if(i==3){d=d+1;}
                alert("第一題:"+flag1);
                document.getElementById('c1').value=a ;
                document.getElementById('c2').value=b ;
                document.getElementById('c3').value=c ;
                document.getElementById('c4').value=d ;
                  break;
              }
    }
for(var i=0;i<radio2.length;i++)
   {if(radio2.item(i).checked==true)
             {flag2=i+1;
                if(i==0){a=a+1;}
                if(i==1){b=b+1;}
                if(i==2){c=c+1;}
                if(i==3){d=d+1;}
                alert("第二題:"+flag2);
                document.getElementById('c1').value=a ;
                document.getElementById('c2').value=b ;
                document.getElementById('c3').value=c ;
                document.getElementById('c4').value=d ;
                  break;
              }
    }
for(var i=0;i<radio3.length;i++)
   {if(radio3.item(i).checked==true)
             {flag3=i+1;
                if(i==0){a=a+1;}
                if(i==1){b=b+1;}
                if(i==2){c=c+1;}
                if(i==3){d=d+1;}
                alert("第三題:"+flag3);
                document.getElementById('c1').value=a ;
                document.getElementById('c2').value=b ;
                document.getElementById('c3').value=c ;
                document.getElementById('c4').value=d ;
                  break;
              }
    }

for(var i=0;i<radio4.length;i++)
   {if(radio4.item(i).checked==true)
             {flag4=i+1;
                if(i==0){a=a+1;}
                if(i==1){b=b+1;}
                if(i==2){c=c+1;}
                if(i==3){d=d+1;}
                alert("第四題:"+flag4);
                document.getElementById('c1').value=a ;
                document.getElementById('c2').value=b ;
                document.getElementById('c3').value=c ;
                document.getElementById('c4').value=d ;
                  break;
              }
    }
drawChart() ;
   }
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['c1',    n1],
          ['c2',    n2],
          ['c3',    n3],
          ['c4',    n4]
        ]);

        var options = {
          title: 'My Daily Activities'
        };

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

        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
<h1>你選了什麼?</h1>
<input name="v1" type="radio" value="300年">300年          
<input name="v1" type="radio" value="400年">400年      
<input name="v1" type="radio" value="500年">500年         
<input name="v1" type="radio" value="1000年">1000年
<br>
<h1>你選了什麼?</h1>
<input name="v2" type="radio" value="300年">300年          
<input name="v2" type="radio" value="400年">400年      
<input name="v2" type="radio" value="500年">500年         
<input name="v2" type="radio" value="1000年">1000年
<br>
<h1>你選了什麼?</h1>
<input name="v3" type="radio" value="300年">300年          
<input name="v3" type="radio" value="400年">400年      
<input name="v3" type="radio" value="500年">500年         
<input name="v3" type="radio" value="1000年">1000年
<br>
<h1>你選了什麼?</h1>
<input name="v4" type="radio" value="300年">300年          
<input name="v4" type="radio" value="400年">400年      
<input name="v4" type="radio" value="500年">500年         
<input name="v4" type="radio" value="1000年">1000年
<br>


c1: 
 <input type="text" name="FirstName" id="c1" <br><br/> 

 c2:
 <input type="text" name="address" id="c2" <br></br>

 c3:
 <input type="text" name="address" id="c3" <br></br>
c4:
 <input type="text" name="address" id="c4" <br></br>

<input type="button" value="autmit" onclick="check1() "/>
<input type="button" value="random" onclick="random() "/>
    <div id="piechart" style="width: 900px; height: 500px;"></div>
  </body>
</html>

arrow
arrow
    全站熱搜

    D0389097 發表在 痞客邦 留言(0) 人氣()