Chart will not show in html file when chart code is placed in an external js file.

303 views
Skip to first unread message

df2...@student.american.edu

unread,
Nov 13, 2014, 10:28:23 AM11/13/14
to google-visua...@googlegroups.com
Good Morning,

I am new to Google Charts. I have taken the code for a Google line chart and placed it in an external javascript file.

I've linked the js file to the html file, but the chart will not appear on the page. What am I doing wrong.

My html page is here: http://media.tastyjournalism.com/au535/frazier/week-2/ It is based on the bootstrap framework.

My javascript is below. This file can also be seen here: http://media.tastyjournalism.com/au535/frazier/week-2/js/charts.js


<script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Year', 'Number Commissioned'],
          ['1989',1],
		  ['1991',2],
		  ['1992',1],
	      ['1993',3],
		  ['1995',3],
          ['1996',1],
          ['1997',2],
		  ['1998',3],
		  ['1999',1],
		  ['2000',5],
		  ['2002',5],
		  ['2003',1],
		  ['2004',9],
		  ['2005',1],
		  ['2006',8],
		  ['2007',11],
 		  ['2008',18],
		  ['2009',13],
	      ['2010',31],
		  ['2011',12],
		  ['2012',18],
		  ['2013',13],
		  ['2014',6]
        ]);

        var options = {
          title: 'Number of Art Commissioned Each Year'
        };

        var chart = new google.visualization.LineChart(document.getElementById('linechartbyyear'));

        chart.draw(data, options);
      }
    </script>

Thank you in advance for the help.

Delinda




Sergey Grabkovsky

unread,
Nov 13, 2014, 10:31:05 AM11/13/14
to google-visua...@googlegroups.com
You don't need the script tags in your JavaScript file. In fact, that's incorrect syntax. The script tags are there to tell the HTML that the content is JavaScript, but when you're loading a JavaScript file, that's already known.

--
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 google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages