65 lines
2.4 KiB
HTML
65 lines
2.4 KiB
HTML
<html>
|
|
<head>
|
|
<!--Load the AJAX API-->
|
|
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
|
<script type="text/javascript">
|
|
// Load the Visualization API and the piechart package.
|
|
google.load('visualization', '1.0', {'packages':['corechart'],['sankey'});
|
|
|
|
// Set a callback to run when the Google Visualization 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() {
|
|
|
|
// Create the data table.
|
|
var data = new google.visualization.DataTable();
|
|
data.addColumn('string', 'Distro');
|
|
data.addColumn('number', 'Servers');
|
|
data.addRows([
|
|
['Red Hat', 3],
|
|
['Ubuntu', 1],
|
|
['Trisquel', 8],
|
|
['Debian', 1],
|
|
['gNewSense', 2]
|
|
]);
|
|
|
|
// Set chart options
|
|
var options = {'title':'Distro Proportions Among Servers',
|
|
'width':400,
|
|
'height':300};
|
|
|
|
// Instantiate and draw our chart, passing in some options.
|
|
var pie_chart = new google.visualization.PieChart(document.getElementById('pie_chart'));
|
|
var bar_chart = new google.visualization.BarChart(document.getElementById('bar_chart'));
|
|
|
|
// The select handler. Call the chart's getSelection() method
|
|
function selectHandler() {
|
|
var selectedItem = pie_chart.getSelection()[0];
|
|
if (selectedItem) {
|
|
var distro = data.getValue(selectedItem.row, 0);
|
|
alert('The user selected ' + distro);
|
|
}
|
|
}
|
|
|
|
// Listen for the 'select' event, and call my function selectHandler() when
|
|
// the user selects something on the chart.
|
|
google.visualization.events.addListener(pie_chart, 'select', selectHandler);
|
|
|
|
pie_chart.draw(data, options);
|
|
bar_chart.draw(data, options);
|
|
}
|
|
</script>
|
|
</head>
|
|
|
|
<body>
|
|
<!--Div that will hold the pie chart-->
|
|
<div id="pie_chart" style="display: inline; float: left;"></div>
|
|
<!--Div that will hold the bar chart-->
|
|
<div id="bar_chart" style="display: inline; float: left;"></div>
|
|
<!--Div that will hold the Sankey chart-->
|
|
<div id="Sankey_chart" style="display: inline; float: left;"></div>
|
|
</body>
|
|
</html>
|