I am trying to create several google charts but I cannot get it to work. I tried everything I could find on Stack Overflow. I recently tried to fix this , but it did not work. I think I'm missing something. Can someone see something wrong with the code as it is now?
Expected Behavior:
The page displays a histogram. Then, a line graph is displayed below the histogram.
Current behavior:
The page displays a histogram. The line graph is not displayed.
Here is the JSFiddle . On the side of the note, JavaScript seems to work inline in JSFiddle. If I moved it to a JavaScript section, it did not work properly. Maybe this has something to do with the external resource that was called?
Regardless of the fact I'm currently doing all this for this experiment.
HTML:
<!DOCTYPE html>
<html>
<head>
<script src="https://www.google.com/jsapi" type="text/javascript">
</script>
<script type="text/javascript">
google.load('visualization', '1.1', {
packages: ['line', 'bar', 'corechart']
});
google.setOnLoadCallback(drawChart);
function drawChart() {
var BarData = new google.visualization.arrayToDataTable([
['', 'Customer', 'Segment Avg'],
['TTM Sales', 4, 2],
['TTM Orders', 5, 3],
['TTM Categories', 7, 4]
]);
var LineData = new google.visualization.arrayToDataTable([
['Year', 'Customer', 'Segment Avg'],
['2011', 4, 5],
['2012', 5, 3],
['2013', 4, 2]
]);
var BarOptions = {
chart: {
title: 'Performance',
},
width: 900,
height: 500
};
var LineOptions = {
chart: {
title: 'Sales History'
},
width: 900,
height: 500
};
var BarChart = new google.charts.Bar(document.getElementById(
'bar_chart'));
BarChart.draw(BarData, BarOptions);
var LineChart = new google.charts.Line(document.getElementById(
'line_chart'));
LineChart.draw(LineData, LineOptions);
};
</script>
<title>Test Chart Page</title>
</head>
<body>
<div id="bar_chart"></div>
<div id="line_chart"></div>
</body>
</html>