2016年5月13日 星期五

圓餅圖

圓餅圖

https://google-developers.appspot.com/chart/interactive/docs/gallery/piechart#overview

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

改成2

<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',     2],
          ['Eat',      2],
          ['Commute',  2],
          ['Watch TV', 2],
          ['Sleep',    2]
        ]);

        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>





改 drawChart() 


<html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
function add() {
            var a ;
            var b ;
            alert('result value');
            }

      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
      var a ;
      a=3;

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

        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>
<input type="button" value="submit" onclick="function drawChart()"/>
  </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);
   var a;
  function check() {
            var radio1=document.getElementsByName("v1");
 for(var i=0;i<radio1.length;i++)
   {
         if(radio1.item(i).checked==true)
             {
     flag1=1+i;
     alert(radio1.item(i).value);
                  break;
       }
   }
}
 function add() {
            var a ;
            var b ;
            alert('result value');
}

                 function drawChart() {
 var a ;
 a=3;
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     a],
          ['Eat',      2],
          ['Commute',  2],
        ]);

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

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

        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
<h1>1、你選了什麼?</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、你選了什麼?</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>
 <input type="button" value="submit" onclick="check() "/>

    <div id="piechart" style="width: 900px; height: 500px;"></div>
 
  </body>
</html>

沒有留言:

張貼留言