欧美成人精品手机在线观看_69视频国产_动漫精品第一页_日韩中文字幕网 - 日本欧美一区二区

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

JS技巧:avascript繪制分析曲線圖

admin
2010年8月17日 23:55 本文熱度 3956

最近開發(fā)彩票分析網(wǎng)站,需要用到j(luò)s繪制分析曲線圖。
參考網(wǎng)上的繪圖代碼,自己封裝了一個繪圖類,給大家做一個參考。



引用方法:


new gov.Graphic(par1,par2,par3);


par1 為繪圖數(shù)據(jù)


var data=new period([0,10,22,13,34,25,28,26,30,35,28,34,39,28,26,50,35,28,34,39,55],//y軸數(shù)據(jù)[188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,
204,205,206,207,208]//x軸數(shù)據(jù)
);


par2 為繪圖的容器層id


par3 為繪圖樣式參數(shù),可選參數(shù)


默認(rèn)值:
{
       height:170,                 //繪圖區(qū)域高度
       maxHeight:50,              //y軸最高數(shù)值
       barDistance:26,           //x軸坐標(biāo)間距
       topDistance:0,             //上部填充
       bottomDistance:0,        //底部填充
       leftDistance:20,            //左部填充
       pointWidth:5,               //坐標(biāo)點寬度
       pointHeight:5,             //坐標(biāo)點高度
       pointColor:"#ff0000",     //坐標(biāo)點顏色
       lineColor:"#ffd43a",       //連接線顏色
       valueWidth:20,            //y軸數(shù)值寬度
       valueColor:"#000",       //y軸數(shù)值顏色
       timeWidth:20,             //x軸數(shù)值寬度
       timeColor:"#000",       //x軸數(shù)值顏色
       disvalue:true,             //是否顯示y軸數(shù)值
       distime:true              //是否顯示x軸數(shù)值
}


運行代碼框
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標(biāo)題文檔</title>
<script>
var gov=new Object();
var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}
}
Object.extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
var $ = function(elem) {
if (arguments.length > 1) {
for (var i = 0, elems = [], length = arguments.length; i < length; i++)
elems.push($(arguments[i]));
return elems;
}
if (typeof elem == 'string') {
return document.getElementById(elem);
} else {
return elem;
}
};
var period =  Class.create();
period.prototype = {
initialize:function(value,time){
this.value = value;
this.time = time;
}
};
gov.Graphic = Class.create();
gov.Graphic.prototype={
initialize: function(data,elm,options){
this.setOptions(options);
this.entity=document.createElement("div");
this.pointBox=$(elm);
this.showPointGraphic(data);
},
setOptions: function(options) {
this.options = {
height:170,                 //繪圖區(qū)域高度
maxHeight:50,              //y軸最高數(shù)值
barDistance:26,           //x軸坐標(biāo)間距
topDistance:0,             //上部填充
bottomDistance:0,        //底部填充
leftDistance:20,
pointWidth:5,               //坐標(biāo)點寬度
pointHeight:5,             //坐標(biāo)點高度
pointColor:"#ff0000",     //坐標(biāo)點顏色
lineColor:"#ffd43a",       //連接線顏色
valueWidth:20,            //y軸數(shù)值寬度
valueColor:"#000",       //y軸數(shù)值顏色
timeWidth:20,             //x軸數(shù)值寬度
timeColor:"#000",       //x軸數(shù)值顏色
disvalue:true,             //是否顯示y軸數(shù)值
distime:true              //是否顯示x軸數(shù)值
}
Object.extend(this.options, options || {});
},
showPointGraphic:function(data,obj)
{
var This=this;
var showPoints=new Array();
var values=new Array();
var times=new Array();
This.points=data;
This.count=data.value.length;
for(var i=0;i<This.count;i++)
{
var showPoint=document.createElement("div");
var spanValue=document.createElement("span");
var spanTime=document.createElement("span");
showPoint.height=This.points.value[i];
showPoint.value=This.points.value[i];
showPoint.time=This.points.time[i];
showPoint.style.backgroundColor=this.options.pointColor;
showPoint.style.fontSize="0px";
showPoint.style.position="absolute";
showPoint.style.zIndex ="999";
showPoint.style.width=this.options.pointWidth+"px";
showPoint.style.height=this.options.pointHeight+"px";
showPoint.style.top=this.options.topDistance+"px";
spanValue.style.position="absolute";
spanValue.style.width=this.options.valueWidth+"px";
spanValue.style.textAlign="center";
spanValue.style.color=this.options.valueColor;
spanValue.style.zIndex ="999";
spanTime.style.position="absolute";
spanTime.style.width=this.options.timeWidth+"px";
spanTime.style.textAlign="center";
spanTime.style.color=this.options.timeColor;
var timeHeight=15;
var valueHeight=21;
if(!this.options.disvalue) {
spanValue.style.display="none";
valueHeight=this.options.pointHeight;
}
if(!this.options.distime) {
spanTime.style.display="none";
timeHeight=0;
}
var left;
if(showPoints.length!=0){
left=parseInt(showPoints[showPoints.length-1].style.left)+parseInt(showPoints[showPoints.length-1].style.width)+this.options.barDistance;
}
else{
left=this.options.leftDistance;
}
showPoint.style.left=left+"px";
spanValue.style.left=left+parseInt((this.options.pointWidth-this.options.valueWidth)/2)+"px";
spanTime.style.left=left+parseInt((this.options.pointWidth-this.options.timeWidth)/2)+"px";
if(showPoint.height>this.options.maxHeight)
{
showPoint.height=this.options.maxHeight;
}
spanValue.innerHTML=showPoint.value;
spanTime.innerHTML=showPoint.time;
showPoints.push(showPoint);
values.push(spanValue);
times.push(spanTime);
This.entity.appendChild(showPoint);
This.entity.appendChild(spanValue);
This.entity.appendChild(spanTime);
var percentage=showPoints[i].height/this.options.maxHeight||0;
var pointTop=(this.options.height-this.options.topDistance-this.options.bottomDistance-timeHeight-valueHeight)*percentage;
showPoints[i].style.top=(this.options.height-this.options.bottomDistance-pointTop-timeHeight-this.options.pointHeight)+"px";
values[i].style.top=(this.options.height-this.options.bottomDistance-pointTop-timeHeight-valueHeight)+"px";
times[i].style.top=this.options.height-this.options.bottomDistance-timeHeight+"px";
}
var _leng=showPoints.length
for(var i=0;i<_leng;i++)
{
if(i>0)
{
This.drawLine(parseInt(showPoints[i-1].style.left),
parseInt(showPoints[i-1].style.top),
parseInt(showPoints[i].style.left),
parseInt(showPoints[i].style.top)
);
}
}
This.Constructor.call(This);
},
drawLine:function(startX,startY,endX,endY)
{
var xDirection=(endX-startX)/Math.abs(endX-startX);
var yDirection=(endY-startY)/Math.abs(endY-startY);
var xDistance=endX-startX;
var yDistance=endY-startY;
var xPercentage=1/Math.abs(endX-startX);
var yPercentage=1/Math.abs(endY-startY);
if(Math.abs(startX-endX)>=Math.abs(startY-endY))
{
var _xnum=Math.abs(xDistance)
for(var i=0;i<=_xnum;i++)
{
var point=document.createElement("div");
point.style.position="absolute";
point.style.backgroundColor=this.options.lineColor;
point.style.fontSize="0";
point.style.width="1px";
point.style.height="1px";
startX+=xDirection;
point.style.left=startX+this.options.pointWidth/2+"px";
startY=startY+yDistance*xPercentage;
point.style.top=startY+this.options.pointHeight/2+"px";
this.entity.appendChild(point);
}
}
else
{
var _ynum=Math.abs(yDistance)
for(var i=0;i<=_ynum;i++)
{
var point=document.createElement("div");
point.style.position="absolute";
point.style.backgroundColor=this.options.lineColor;
point.style.fontSize="0";
point.style.width="1px";
point.style.height="1px";
startY+=yDirection;
point.style.top=startY+this.options.pointWidth/2+"px";
startX=startX+xDistance*yPercentage;
point.style.left=startX+this.options.pointHeight/2+"px";
this.entity.appendChild(point);
}
}
},
Constructor:function()
{
this.entity.style.position="absolute";
this.pointBox.innerHTML="";
this.pointBox.appendChild(this.entity);
}
}
window.onload=function(){
var data=new period([0,10,22,13,34,25,28,26,30,35,28,34,39,28,26,50,35,28,34,39,55],//y軸數(shù)據(jù)
[188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208]//x軸數(shù)據(jù)
);
var data1=new period([48,23,10,2,12,8,24,25,15,35,25,14,42,58,46,25,12,8,14,28,42],//y軸數(shù)據(jù)
[188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208]//x軸數(shù)據(jù)
);
new gov.Graphic(data,"box");
new gov.Graphic(data1,"box1",{ pointColor:"#3366ff",lineColor:"#33ffff"});
}
</script>
<style type="text/css">
body,td,th {
font-family: Arial, Helvetica, sans-serif;

margin:0px;
padding:0px;
}
#box,#box1{
padding:13px 0px 10px;
padding-left:28px;
width:677px;
height:180px;
background:url(/articleimg/2009/03/6562/bg.jpg) no-repeat;
}
</style></head>
<body>
<div id="box"></div>
<div id="box1"></div>
</body>
</html>
 [Ctrl+A 全部選擇 提示:你可先修改部分代碼,再按運行]


源碼下載(點擊下載)


該文章在 2010/8/17 23:55:09 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運作、調(diào)度、堆場、車隊、財務(wù)費用、相關(guān)報表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點,圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務(wù)都免費,不限功能、不限時間、不限用戶的免費OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved