<!doctype html>
<html lang="ja">
<head>
<title>棒グラフデコレーションサンプル</title>
<meta charset="UTF-8" />
<!--これが無いとresizeableマークが表示されず -->
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script type="text/javascript" src="./js/jquery-2.2.3.js"></script>
<script type="text/javascript" src="./js/Chart.js"></script>
<!--draggable/resizeableにはこのjsが必須 -->
<script type="text/javascript" src="./js/jquery-ui-1.11.4.custom/jquery-ui.js"></script>
<style>
<!--
#resize {
background-color : #ffffff;
border:solid 1px #000000;
}
#drag {
border:solid 1px #ffffff;
}
.moveicon {
cursor:move;
}
//-->
</style>
<script type="text/javascript">
<!--
$(function(){
Chart.defaults.global.legend.display=false;
Chart.defaults.global.responsive=false;
$("#GraphCanvas").width(300);
$("#GraphCanvas").height(300);
var ctxChart = $("#GraphCanvas");
var graphObj = null;
var postRequest = function (category) {
var reqparam = {
"category" : category
};
$.ajax({
url : "./doughnutchartdraw2.xhtml",
dataType: "json",
type : "post",
data : JSON.stringify(reqparam),
}).done(function(resData) {
drawChart(resData);
}).fail(function(resData) {
//console.log("faild resData["+JSON.stringify(resData,null,' ')+"]");
});
}
$("#drag").draggable({
stop:function(event, ui) {
var position = $(this).position();
if(position.left < 0) {
$("#drag").css("left", 0);
}
if(position.top < 0) {
$("#drag").css("top", 0);
}
}
});
$("#resize").resizable({
stop:function() {
if(graphObj != null) {
graphObj.resize();
GhraphRefresh();
}
}
});
var drawChart = function(response) {
graphObj = new Chart(ctxChart,{
type: 'bar',
data: response,
options:{
scales: {
yAxes: [{
stacked: true
}]
}
}
});
graphObj.resize();
GhraphRefresh();
}
var GhraphRefresh = function() {
var rwidth = $("#resize").width();
var rheight = $("#resize").height();
$("#GraphCanvas").width(rwidth);
$("#GraphCanvas").height(rheight);
$("#drag").width(rwidth);
$("#drag").height(rheight);
}
$("#draw").click(function(){
var category = $("#category").val();
if(graphObj != null) {
graphObj.destroy();
}
postRequest(category);
});
});
//-->
</script>
</head>
<body>
<form>
<table>
<tr>
<td>
<table>
<tr>
<td>
<span style="font-weight:bold;color:blue;">■Draggable/Resizable な棒グラフサンプル</span>
</td>
</tr>
<tr>
<td>
jQuery-UI を使った棒グラフのデコレーション。<br/>
「グラフを描画」ボタンでグラフが描画されます。<br/>
グラフエリアをつまんで、あちこちに移動できます。<br/>
グラフエリア右下の▼アイコンをつまんで引っ張ると、グラフが伸縮します。<br/>
<br/>
<br/>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
グラフを描画する分類を選択してください。<br />
<br />
<select id="category">
<option value="0">果物の数のグラフ</option>
<option value="1">肉類の数のグラフ</option>
<option value="2">花の数のグラフ</option>
</select>
<input id="draw" type="button" value="グラフを描画" />
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td style="text-align:left;">
<div id="drag" class="ui-widget-content moveicon">
<div id="resize">
<!-- グラフ描画キャンバス -->
<canvas id="GraphCanvas"></canvas>
</div>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
|