﻿function set_chart(opt){
//<概要>
//divとdataを指定すると、その中にグラフを書き込む関数。
//グラフのサイズは、自動的にdivのサイズに調整される。
//
//<引数>
//	opt = {
//		graphDiv: (グラフを入れるdiv), 
//		data: (グラフのデータ)
//	}
//
	$(opt.graphDiv+" div.graphimage").remove();
	var graph = new Array;
	graph.width = $(opt.graphDiv).width();
	graph.height = $(opt.graphDiv).height();
	
	var nowdate = new Date();
	var nowyear = nowdate.getFullYear();
	var nowmonth = nowdate.getMonth() + 1;
	var nowday = nowdate.getDate();
	var nowhours = nowdate.getHours();
	var nowminutes = nowdate.getMinutes();
	var nowseconds = nowdate.getSeconds();
	if (nowmonth.toString().length == 1) {
		nowmonth = "0" + nowmonth;
	}
	nowday = "" + nowday;
	if (nowday.toString().length == 1) {
		nowday = "0" + nowday;
	}
	if (nowhours.toString().length == 1) {
		nowhours = "0" + nowhours;
	}
	if (nowminutes.toString().length == 1) {
		nowminutes = "0" + nowminutes;
	}
	if (nowseconds.toString().length == 1) {
		nowseconds = "0" + nowseconds;
	}
	var strDate = nowyear + nowmonth + nowday + nowhours + nowminutes + nowseconds;
	
	
	if(opt.dirflg){
		graph.data = "chart_xml/chart_" + opt.data + ".xml?rand=" + strDate;
		//graph.data = "chart_xml/chart_" + opt.data + ".xml";
	}else{
		graph.data = "chart_xml/read.php?id=" + opt.data + "&rand=" + strDate;
	}
	
	var str = "<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'";
	str += "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' WIDTH='" + graph.width + "' HEIGHT='" + graph.height + "' id='charts' ALIGN=''>";
	str += "<PARAM NAME=movie VALUE='../charts/charts.swf?library_path=../charts/charts_library&xml_source=";
	str += graph.data;
	str += "'/><PARAM NAME=quality VALUE=high/><PARAM NAME=bgcolor VALUE=#FFFFFF/><param  name='wmode'  value='transparent'><EMBED src='../charts/charts.swf?library_path=../charts/charts_library&xml_source=";
	str += graph.data;
	str += "' quality=high bgcolor=#ffffff width='" + graph.width + "' height='" + graph.height + "' NAME='charts' ALIGN='' swLiveConnect='true' TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer' wmode='transparent'>";
	str += "</EMBED></OBJECT>";
	
	$(opt.graphDiv).append($("<div class='graphimage'>" + str + "</div>"));
	
}
