数据可视化(3)--Google Charts

Google Chart API 是谷歌提供的一项动态生成图表的服务。你可以随时自定义图表,以适应网站的外观和感觉。图表使用HTML5/SVG技术提供给iPhone手机, iPad和Android的跨浏览器兼容性(包括VML较旧版本的IE )和跨平台的可移植性呈现。

官网地址:https://developers.google.com/chart/?hl=zh-cn

运行下面这段代码,可以动态生成一个漂亮的图表

<html>
  <head>
    
    <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 id="chart_div">div>
  body>
html>

效果如下

数据可视化(3)--Google Charts_第1张图片

那么他到底是如何工作的?

绘制chart需要三个库

  • 谷歌JSAPI库
  • 谷歌可视化库(The Google Visualization library)
  • chart自身的库(相应的packages)

这三个库通过两个

你可能感兴趣的:(数据可视化(3)--Google Charts)