<!DOCTYPE html>
<html>
<head>
<title>CPU使用率</title>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="./css/style.css" />
<script type="text/javascript" src="./js/jquery-1.11.2.js"></script>
<![endif]-->
<script type="text/javascript" src="./js/jquery-2.1.3.js"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
<!--
$(function(){
google.charts.load('current', {'packages':['corechart']});
var ws = new WebSocket("ws://localhost:8080/j_Labo/wscpuused.xhtml");
ws.onopen = function(){
};
ws.onclose = function(){
};
ws.onmessage = function(message){
drawVisualization(message.data);
};
ws.onerror = function(event){
alert("エラー");
};
$(window).unload(function() {
ws.send("stop");
});
$("#id_start").click(function() {
ws.send("start");
});
$("#id_stop").click(function() {
ws.send("stop");
});
function drawVisualization(graph_data) {
var json = $.parseJSON(graph_data);
var chart_data = [];
var title_item = ['Time', 'used'];
chart_data.push(title_item);
$.each(json, function(i) {
var data_item = [];
data_item.push(this.time);
data_item.push(this.used);
chart_data.push(data_item);
});
var chart_val = google.visualization.arrayToDataTable(chart_data);
var options = {
title: 'CPU使用率',
colors: ['deepskyblue'],
pointSize: 4,
curveType: 'function',
legend: 'none',
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(chart_val, options);
}
});
//-->
</script>
</head>
<body class="in_background">
<table class="round">
<tr>
<td>
<button id="id_start">開始</button> <button id="id_stop">停止</button>
</td>
</tr>
<tr>
<td>
<div id="chart_div" style="width:100%; height: 500px;"></div>
</td>
</tr>
</table>
</body>
</html>
|