两个相同的谷歌colomn图表不在同一页面中工作,只有一个出现

时间:2015-12-13 10:00:38

标签: javascript jquery charts

<html>   
 <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1.1", {packages:["bar"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Year', 'Sales', 'Expenses', 'Profit'],
          ['2014', 1000, 400, 200],
          ['2015', 1170, 460, 250],
          ['2016', 660, 1120, 300],
          ['2017', 1030, 540, 350]
        ]);

        var options = {
          chart: {
            title: 'Company Performance',
            subtitle: 'Sales, Expenses, and Profit: 2014-2017',
          }
        };       var data1 = google.visualization.arrayToDataTable([
          ['Year', 'Sales', 'Expenses', 'Profit'],
          ['2014', 1000, 400, 200],
          ['2015', 1170, 460, 250],
          ['2016', 660, 1120, 300],
          ['2017', 1030, 540, 350]
        ]);

        var options1 = {
          chart: {
            title: 'Company Performance',
            subtitle: 'Sales, Expenses, and Profit: 2014-2017',
          }
        };

        var chart = new google.charts.Bar(document.getElementById('columnchart_material'));
        chart.draw(data, options);      var chart1 = new google.charts.Bar(document.getElementById('columnchart_material1'));
        chart1.draw(data, options1);
      }
    </script>   
   </head>   
   <body>
     <div id="columnchart_material" style="width: 900px; height: 500px;"></div>
     <div id="columnchart_material1" style="width: 900px; height: 500px;"></div>   
   </body> 
  </html>

1 个答案:

答案 0 :(得分:1)

class GameScene: SKScene, SKPhysicsContactDelegate {
    override func didMoveToView(view: SKView) {
    ...
    let backgroundMusic = SKAudioNode(fileNamed: "main.mp3")
    backgroundMusic.autoplayLooped = true
    addChild(backgroundMusic)
    ...
    }
}
 google.load("visualization", "1.1", {packages:["bar"]});
      
        google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Year', 'Sales', 'Expenses', 'Profit'],
          ['2014', 1000, 400, 200],
          ['2015', 1190, 460, 250],
          ['2016', 660, 1120, 300],
          ['2017', 1030, 540, 350]
        ]);

    
        var data1 = google.visualization.arrayToDataTable([
          ['Year', 'Sales', 'Expenses', 'Profit'],
          ['2014', 1000, 400, 200],
          ['2015', 1170, 460, 250],
          ['2016', 660, 1120, 300],
          ['2017', 1030, 540, 350]
        ]);

        var options = {
          chart: {
            title: 'Company Performance',
            subtitle: 'Sales, Expenses, and Profit: 2014-2017'
          }
        };   

        var options1 = {
          chart: {
            title: 'Company Performance',
            subtitle: 'Sales, Expenses, and Profit: 2014-2017'
          }
        };

        var chart = new google.charts.Bar(document.getElementById('columnchart_material'));
        google.visualization.events.addOneTimeListener(chart, 'ready', function(){
             //render chart2 once chart1 is rendered
             var chart1 = new google.charts.Bar(document.getElementById("columnchart_material1"));
             chart1.draw(data1, options1);     
        });
        chart.draw(data, options);

      }