How to create two different charts on the same page?

29 views
Skip to first unread message

barabashkakvn

unread,
Sep 7, 2016, 8:44:32 AM9/7/16
to Google Visualization API
Code #1:
<html>
 
<head>
   
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
   
<script type="text/javascript">
      google
.charts.load('current', {'packages':['bar']});
      google
.charts.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 chart = new google.charts.Bar(document.getElementById('columnchart_material'));

        chart
.draw(data, options);
     
}
   
</script>
 
</head>
 
<body>
   
<div id="columnchart_material" style="width: 900px; height: 500px;"></div>
 
</body>
</html>


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

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

       
var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
        chart
.draw(data, options);
     
}
   
</script>
 
</head>
 
<body>
   
<div id="donutchart" style="width: 900px; height: 500px;"></div>
 
</body>
</html>


As these two codes are combined into one?
Reply all
Reply to author
Forward
0 new messages