This commit is contained in:
Arjun Patel
2017-09-15 22:34:05 -07:00
parent 862ca4bd3b
commit 3e059c2b58
2 changed files with 19 additions and 82 deletions
+16 -57
View File
@@ -1,63 +1,22 @@
google.charts.load('current', {'packages':['corechart']}); google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart); google.charts.setOnLoadCallback(drawChart);
google.charts.load('current', {'packages':['bar']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() { function drawChart() {
var data = google.visualization.arrayToDataTable([ var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'], ['Task', 'Hours per Day'],
['Food and Dining', 11], ['Work', 11],
['Clothing', 2], ['Eat', 2],
['Entertainment', 2], ['Commute', 2],
['Transportation', 7], ['Watch TV', 2],
['Other', 1] ['Sleep', 7]
]); ]);
var options = { var options = {
title: 'My Daily Activities' title: 'My Daily Activities'
}; };
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options); chart.draw(data, options);
} }
};
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Category', 'You', 'Average 18 Year Old'],
['Food and Dining', 1000, 400],
['Utilities', 1170, 460],
['Clothing', 660, 120],
['Entertainment', 1030, 540],
['Transportation', 1030, 540],
['Other', 1030, 540]
]);
var options = {
chart: {
title: 'Comparing Spending Habits',
subtitle: 'Based on other 18 year olds',
},
bars: 'horizontal', // Required for Material Bar Charts.
hAxis: {
format: 'decimal'
},
height: 400,
colors: ['#1b9e77', '#d95f02', '#7570b3']
};
var chart = new google.charts.Bar(document.getElementById('chart_div'));
chart.draw(data, google.charts.Bar.convertOptions(options));
var btns = document.getElementById('btn-group');
btns.onclick = function(e) {
if (e.target.tagName === 'BUTTON') {
options.hAxis.format = e.target.id === 'none' ? '' : e.target.id;
chart.draw(data, google.charts.Bar.convertOptions(options));
}
}
}
+3 -25
View File
@@ -1,32 +1,10 @@
<<html> <html>
<head> <head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript"> <script type="text/javascript" src="mainJs.js"></script>
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'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
</head> </head>
<body> <body>
<div id="piechart" style="width: 900px; height: 500px;"></div> <div id="piechart" style="width: 900px; height: 500px;"></div>
</body> </body>
</html> </html>