Yes, you can draw multiple charts. You need to make a few adjustments to
your code in order to make it work. First, you only want to load the
Visualization API once, and use one callback. Second, your two drawChart
functions need to have different names; when you create a new function with
the same name as an existing function, you overwrite the existing
function. Third, you need two unique container divs for your charts to
draw in. Here's one way you might organize it:
function drawChart1 () {
// draw the first chart
}
function drawChart2 () {
// draw the second chart
}
function init () {
drawChart1();
drawChart2();
}
google.load('visualization', '1', {packages:['corechart'], callback: init});
and in your HTML:
<div id="chart_div_1" style="width: 400px; height: 500px;"></div>
<div id="chart_div_2" style="width: 400px; height: 500px;"></div>
On Tuesday, November 12, 2013 6:37:08 PM UTC-5, Corina Campbell wrote:
>
> I have a question about whether it is possible to embed two GoogleCharts
> into one HTML code. If so are there any tricks? Here is my unsuccssful
> attempt at it. Please advise.
>
>
> <html>
> <head>
> <script type="text/javascript" src="https://www.google.com/jsapi
> "></script>
> <script type="text/javascript">
> google.load("visualization", "1", {packages:["corechart"]});
> google.setOnLoadCallback(drawChart);
> function drawChart() {
> var data = google.visualization.arrayToDataTable([
> ['Month', 'Hostile Deaths', 'Non-Hostile Deaths'],
>
> ['Jan', 78, 5],
> ['Feb', 70, 11],
> ['Mar', 71, 10],
> ['Apr', 96, 8],
> ['May', 120, 6,],
> ['Jun', 93, 8],
> ['Jul', 67, 13],
> ['Aug', 56, 28],
> ['Sept', 43, 23],
> ['Oct', 29, 9],
> ['Nov', 27, 9],
> ['Dec', 14, 9,]
> ]);
>
> var options = {
> title: 'Operation Iraqi Freedom US Military Deaths, 2007',
> backgroundColor: ['#999999'],
> colors:['#cc0000','#ff6600'],
> tooltip: {isHtml: true}
>
> };
>
> var cha
> var chart = new
> google.visualization.LineChart(document.getElementById('chart_div'));
> chart.draw(data, options);
> }
>
> </script>
>
> <script type="text/javascript">
> google.load("visualization", "1", {packages:["corechart"]});
> google.setOnLoadCallback(drawChart);
> function drawChart() {
> var data = google.visualization.arrayToDataTable([
> ['Month', 'Hostile Deaths', 'Non-Hostile Deaths'],
>
> ['Jan', 8, 8],
> ['Feb', 11, 6],
> ['Mar', 4, 5],
> ['Apr', 13, 6],
> ['May', 11, 13],
> ['Jun', 10, 5],
> ['Jul', 5, 3],
> ['Aug', 4, 3],
> ['Sept', 4, 6],
> ['Oct', 2, 7],
> ['Nov', 2, 9],
> ['Dec', 0, 3,]
> ]);
>
> var options = {
> title: 'Operation Iraqi Freedom US Military Deaths, 2009',
> backgroundColor: ['#999999'],
> colors:['#cc0000','#ff6600'],
> tooltip: {isHtml: true}
> };
>
> var cha
> var chart = new
> google.visualization.LineChart(document.getElementById('chart_div'));
> chart.draw(data, options);
> }
> </script>
>
> </head>
> <body>
> <div id="chart_div" style="width: 400px; height: 500px;"></div>
> </body>
> </html>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.