2016年6月21日 星期二

彩色圓餅圖隨機變色的第二種方法
</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);

 var a ;
 var b ;
 var c ;
function add() {
a=0;
b=0;
c=0;
d=0;
e=0;
f=0;
g=0;
h=0;
j=0;
var maxNum = 3;
var minNum = 1;
var radio1=document.getElementsByName("v1");
var radio2=document.getElementsByName("v2");
var radio3=document.getElementsByName("v3");


var i=0 ;
i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
     

if(i==1){
       a=1;
}
    if(i==2) {
        b=1;
    }
    if(i==3) {
        c=1;
    }


               
 

 
var k=0 ;
k = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum ;
   
       if(k==1){
       d=1;

}
    if(k==2) {
        e=1;
    }
    if(k==3) {
        f=1;
    }
             
     



var o ;
o = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
 
       if(o==1){
       g=1;

}
    if(o==2) {
        h=1;
}
   
   if(o==3) {
        j=1;
    }

             
 
            drawChart();
        }


        function drawChart() {

        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     a],
          ['Eat',      b],
          ['Commute',  c],
          ['Commute',  d],
          ['Commute',  e],
          ['Commute',  f],
          ['Commute',  g],
          ['Commute',  h],
          ['Commute',  j],
        ]);

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

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

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



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

  </body>
</html>>

沒有留言:

張貼留言