iT邦幫忙

2017 iT 邦幫忙鐵人賽
DAY 27
0
Modern Web

ASP.NET (Web Form)快速入門,全程Youtube影片教學系列 第 27

網頁與圖表 -- Google Chart #1

比ASP.NET Chart控制項更好的選擇 - Gooogle Charts with JavaScript

YouTube影片 -- https://youtu.be/lXkmN4tl_ew
Yes

範例如下(基本架構):
各位可以發現:

  1. 一開始先設定(引用)必要的 JavaScript與API
  2. 然後放入一些基本資料(RowData)
  3. 最後.......搞定。圖表會出現在這裡
<div id="chart_div"></div>

2016/11月補充說明,
第一列的 script似乎已經更換(請注意原廠網站的範例,但我使用本文的 "舊" 寫法仍可運作)

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

原本的範例(程式碼)

<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

      // Load the Visualization API and the piechart package.
      google.load('visualization', '1.0', {'packages':['corechart']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(drawChart);

      // Callback that creates and populates a data table,
      // instantiates the pie chart, passes in the data and
      // draws it.
      function drawChart() {

        // Create the data table.  ***原始資料***

        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Topping');
        data.addColumn('number', 'Slices');
        data.addRows([
          ['Mushrooms', 3],
          ['Onions', 1],
          ['Olives', 1],
          ['Zucchini', 1],
          ['Pepperoni', 2]
        ]);

        // ************差異之處****************
        // Set chart options
        var options = {'title':'How Much Pizza I Ate Last Night',
                       'width':400,
                       'height':300};

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
  </head>

  <body>
    <!--Div that will hold the pie chart-->
    <div id="chart_div"></div>
  </body>
</html>

下一篇文章 -- http://ithelp.ithome.com.tw/articles/10188238
我們要把產生圖表的「真實數據」,從資料庫裡面取得


上一篇
會員登入 - ASP.NET Identity
下一篇
網頁與圖表 -- Google Chart #2 (JavaScript與後置程式碼)
系列文
ASP.NET (Web Form)快速入門,全程Youtube影片教學30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言