<html> <head> <!--Load the AJAX API--> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> // Load the Visualization API and the piechart package. google.load('visualization', '1', {'packages':['piechart']}); // Set a callback to run when the API is loaded. google.setOnLoadCallback(drawChart); // Callback that creates and populates a data table, instantiates the pie chart, passes in the data and draws it. function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('string', 'Activity'); data.addColumn('number', 'Percentage of Time Spent'); data.addRows(3); data.setValue(0, 0, 'Joking about it on twitter'); data.setValue(0, 1, 80); data.setValue(1, 0, 'Writing code'); data.setValue(1, 1, 10); data.setValue(2, 0, 'Presenting to my dogs'); data.setValue(2, 1, 10); var chart = new google.visualization.PieChart(document.getElementById('chart_div')); chart.draw(data, {width: 800, height: 600, is3D: true, title: 'Time Jason Spent Preparing For This Presentation'}); } </script> </head> <body> <!--Div that will hold the pie chart--> <div id="chart_div"></div> </body> </html>
Codexploration
<!--Load the AJAX API--> <script type="text/javascript"
<script type="text/javascript"> // Load the Visualization API and the piechart package. google.load ('visualization', '1', {'packages':['piechart']}); // Set a callback to run when the API is loaded. google.setOnLoadCallback (drawChart);
[...]
Codexploration
function drawChart() { var data = new google.visualization.DataTable (); data.addColumn ('string', 'Activity'); data.addColumn ('number', 'Percentage of Time Spent'); data.addRows (3); data.setValue (0, 0, 'Joking about it on twitter'); data.setValue (0, 1, 80); data.setValue (1, 0, 'Writing code'); data.setValue (1, 1, 10); data.setValue (2, 0, 'Presenting to my dogs'); data.setValue (2, 1, 10);
[...]
Codexploration
var chart = new google.visualization.PieChart (document.getElementById('chart_div'));
chart.draw (data, {width: 800, height: 600, is3D: true, title: 'Time Jason Spent Preparing For This Presentation'});
} // function drawChart()
Codexploration
<body> <!--Div that will hold the pie chart--> <div id="chart_div"></div> </body>
JavaScript Object Notation (JSON)
var data = new google.visualization.DataTable( { cols: [{id: 'activity', label: 'Activity', type: 'string'}, {id: 'percentage', label: 'Time Spent', type: 'number'}], rows: [{c:[{v: 'Joking about it on twitter'}, {v: 40}]}, {c:[{v: 'Writing code'}, {v: 10}]}, {c:[{v: 'Playing in the yard with my dogs'}, {v: 50}]}]
0 comments
Post a comment