2016年5月20日 星期五

隨機變數產生圓餅圖

<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,b,c;
      a=0;
      b=0;
      c=0;
      d=0;
      function add() {

 var radio1 = document.getElementsByName("v1");
 var radio2 = document.getElementsByName("v2");

   for(var i=0;i<radio1.length;i++)
   {
     if(radio1.item(i).checked==true)
     {
i = i+1
     alert(i);
if (i==1)
  {
a=a+1;
  }
if (i==2)
  {
b=b+1;
  }
if (i==3)
  {
c=c+1;
  }


     
     document.getElementById('c1').value=a;
break;
     }
   }
 for(var i=0;i<radio2.length;i++)
   {
     if(radio2.item(i).checked==true)
     {
i = i+1
     alert(i);
     if (i==1)
  {
a=a+1;
  }

     document.getElementById('c1').value=a;
break;
     }
   }






      drawChart();
      }

      function drawChart() {
       a=Math.floor(Math.random()*100);
       b=Math.floor(Math.random()*100);
       c=Math.floor(Math.random()*100);
       d=Math.floor(Math.random()*100);
       var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     a],
          ['Eat',      b],
          ['Commute',  c],
          ['Sleep',  d],
        ]);

        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="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="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="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>

 <input type="button" value="submit" onclick="add()"/>

 <input type="button" value="randon" onclick="drawChart()"/>
    <div id="piechart" style="width: 900px; height: 500px;"></div>

  </body>
</html>

2016年5月13日 星期五

圓餅圖

<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;
    function add() {
a=0;
b=0;
c=0;
var radio1=document.getElementsByName("v1");
var radio2=document.getElementsByName("v2");
var radio3=document.getElementsByName("v3");
 for(var i=0;i<radio1.length;i++){
     if(radio1.item(i).checked==true)        {
       i=i+1;
       alert(i);
if(i==1){
       a=a+1;
}
else
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
       }
   }
for(var i=0;i<radio2.length;i++){
     if(radio2.item(i).checked==true)        {
       i=i+1;
       alert(i);
       if(i==1){
       a=a+1;
}
else
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
       }
   }
for(var i=0;i<radio3.length;i++){
     if(radio3.item(i).checked==true)        {
       i=i+1;
       alert(i);
       if(i==1){
       a=a+1;
}
else
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
       }
   }
            drawChart();
        }  
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',   a],
          ['Eat',      b],
          ['Commute',  c],
        ]);
        var options = {
          title: 'My Daily Activities'
        };

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

        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
<h1>
你選了什麼&#65311;
</h1>
<input name="v1" type="radio" value="300年" />300年
<input name="v1" type="radio" value="400年" />400年
<input name="v1" type="radio" value="1000年" />1000年
<br>
<h1>
你選了什麼&#65311;
</h1>
<input name="v2" type="radio" value="300年" />300年
<input name="v2" type="radio" value="400年" />400年
<input name="v2" type="radio" value="1000年" />1000年
<br>
<h1>
你選了什麼&#65311;
</h1>
<input name="v3" type="radio" value="300年" />300年
<input name="v3" type="radio" value="400年" />400年
<input name="v3" type="radio" value="1000年" />1000年
<br>
c1:<input type="text" id="c1" /><br>
c2:<input type="text" id="c2" /><br>
c3:<input type="text" id="c3" /><br>
   <input type ="button" value="submit" onclick ="add() "/>
    <div id="piechart" style="width: 900px; height: 500px;"></div>
</body>
</html>

2016年5月6日 星期五

加法計算器


<head>
    <title>加法運算器</title>
    <script>
        function add() {
            var a = parseInt(document.getElementById('a').value);
            var b = parseInt(document.getElementById('b').value);
            document.getElementById('result').value =  a+b ;
        }
    </script>
</head>
<body>
    <input id="a" type="text" />+<input id="b" type="text" />
    <button onclick="add()" ></button>
    <output id="result"></output>
</body>
</html>


<html> <head> <title> Form </title> <script> function check1() { var radio1=document.getElementsByName("v1"); for(var i=0;i<radio1.length;i++) { if(radio1.item(i).checked==true) { flag1=1; alert(radio1.item(i).value) ; break; } } } </script> </head> <body> <form action="post.php" method="post" name="add" enctype="multipart/form-data" onSubmit="return check();" > <h1>1、ssss?</h1> <input name="v1" type="radio" value="300年">300年 <input name="v1" type="radio" value="400年">400年 <input name="v1" type="radio" value="1000年">1000年 <input type="button" value="submit" onclick="check1()" /> </form> </body> </html>
<html> <head> <title> Form </title> <script> function check1() { var radio1=document.getElementsByName("v1"); var radio2=document.getElementsByName("v2"); for(var i=0;i<radio1.length;i++) { if(radio1.item(i).checked==true) { flag1=1+i; break; } } for(var i=0;i<radio1.length;i++) { if(radio2.item(i).checked==true) { flag2=1+i; break; } } document.write(flag1,flag2); } </script> </head> <body> <form action="post.php" method="post" name="add" enctype="multipart/form-data" onSubmit="return check();" > <h1>1、ssss?</h1> <input name="v1" type="radio" value="300年">300年 <input name="v1" type="radio" value="400年">400年 <input name="v1" type="radio" value="1000年">1000年 <h1>2、ssss?</h1> <input name="v2" type="radio" value="300年">300年 <input name="v2" type="radio" value="400年">400年 <input name="v2" type="radio" value="1000年">1000年 <input type="button" value="submit" onclick="check1()" /> </form> </body> </html>

<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);
      function drawChart() {

        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     11],
          ['Eat',      2],
          ['Commute',  2],
          ['Watch TV', 2],
          ['Sleep',    7]
        ]);

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

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

        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="piechart" style="width: 900px; height: 500px;"></div>
  </body>
</html>