⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chart.js

📁 dojo-0.3.0-ajax开 源 项 目
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*	Copyright (c) 2004-2006, The Dojo Foundation	All Rights Reserved.	Licensed under the Academic Free License version 2.1 or above OR the	modified BSD license. For more information on Dojo licensing, see:		http://dojotoolkit.org/community/licensing.shtml*/dojo.provide("dojo.widget.svg.Chart");dojo.require("dojo.widget.HtmlWidget");dojo.require("dojo.widget.Chart");dojo.require("dojo.math");dojo.require("dojo.html");dojo.require("dojo.svg");dojo.require("dojo.graphics.color");dojo.widget.svg.Chart=function(){	dojo.widget.Chart.call(this);	dojo.widget.HtmlWidget.call(this);};dojo.inherits(dojo.widget.svg.Chart, dojo.widget.HtmlWidget);dojo.lang.extend(dojo.widget.svg.Chart, {	//	widget props	templatePath:null,	templateCssPath:null,	//	state	_isInitialized:false,	hasData:false,	//	chart props	vectorNode:null,	plotArea:null,	dataGroup:null,	axisGroup:null,	properties:{		height:400,	//	defaults, will resize to the domNode.		width:600,		plotType:null,		padding:{			top:10,			bottom:2,			left:60,			right:30		},		axes:{			x:{				plotAt:0,				label:"",				unitLabel:"",				unitType:Number,				nUnitsToShow:10,				range:{					min:0,					max:200				}			},			y:{				plotAt:0,				label:"",				unitLabel:"",				unitType:Number,				nUnitsToShow:10,				range:{					min:0,					max:200				}			}		}	},		fillInTemplate:function(args,frag){		this.initialize();		this.render();	},	parseData:function(){	},	initialize:function(){		this.parseData();			//	begin by grabbing the table, and reading it in.		var table=this.domNode.getElementsByTagName("table")[0];		if (!table) return;				var bRangeX=false;		var bRangeY=false;				//	properties off the table		if (table.getAttribute("width")) this.properties.width=table.getAttribute("width");		if (table.getAttribute("height")) this.properties.height=table.getAttribute("height");		if (table.getAttribute("plotType")) this.properties.plotType=table.getAttribute("plotType");		if (table.getAttribute("padding")){			if (table.getAttribute("padding").indexOf(",") > -1)				var p=table.getAttribute("padding").split(","); 			else var p=table.getAttribute("padding").split(" ");			if (p.length==1){				var pad=parseFloat(p[0]);				this.properties.padding.top=pad;				this.properties.padding.right=pad;				this.properties.padding.bottom=pad;				this.properties.padding.left=pad;			} else if(p.length==2){				var padV=parseFloat(p[0]);				var padH=parseFloat(p[1]);				this.properties.padding.top=padV;				this.properties.padding.right=padH;				this.properties.padding.bottom=padV;				this.properties.padding.left=padH;			} else if(p.length==4){				this.properties.padding.top=parseFloat(p[0]);				this.properties.padding.right=parseFloat(p[1]);				this.properties.padding.bottom=parseFloat(p[2]);				this.properties.padding.left=parseFloat(p[3]);			}		}		if (table.getAttribute("rangeX")){			var p=table.getAttribute("rangeX");			if (p.indexOf(",")>-1) p=p.split(",");			else p=p.split(" ");			this.properties.axes.x.range.min=parseFloat(p[0]);			this.properties.axes.x.range.max=parseFloat(p[1]);			bRangeX=true;		}		if (table.getAttribute("rangeY")){			var p=table.getAttribute("rangeY");			if (p.indexOf(",")>-1) p=p.split(",");			else p=p.split(" ");			this.properties.axes.y.range.min=parseFloat(p[0]);			this.properties.axes.y.range.max=parseFloat(p[1]);			bRangeY=true;		}		var thead=table.getElementsByTagName("thead")[0];		var tbody=table.getElementsByTagName("tbody")[0];		if(!(thead&&tbody)) dojo.raise("dojo.widget.Chart: supplied table must define a head and a body.");		//	set up the series.		var columns=thead.getElementsByTagName("tr")[0].getElementsByTagName("th");	//	should be <tr><..>				//	assume column 0 == X		for (var i=1; i<columns.length; i++){			var key="column"+i;			var label=columns[i].innerHTML;			var plotType=columns[i].getAttribute("plotType")||"line";			var color=columns[i].getAttribute("color");			var ds=new dojo.widget.Chart.DataSeries(key,label,plotType,color);			this.series.push(ds);		}		//	ok, get the values.		var rows=tbody.getElementsByTagName("tr");		var xMin=Number.MAX_VALUE,xMax=Number.MIN_VALUE;		var yMin=Number.MAX_VALUE,yMax=Number.MIN_VALUE;		var ignore = [			"accesskey","align","bgcolor","class",			"colspan","height","id","nowrap",			"rowspan","style","tabindex","title",			"valign","width"		];		for(var i=0; i<rows.length; i++){			var row=rows[i];			var cells=row.getElementsByTagName("td");			var x=Number.MIN_VALUE;			for (var j=0; j<cells.length; j++){				if (j==0){					x=parseFloat(cells[j].innerHTML);					xMin=Math.min(xMin, x);					xMax=Math.max(xMax, x);				} else {					var ds=this.series[j-1];					var y=parseFloat(cells[j].innerHTML);					yMin=Math.min(yMin,y);					yMax=Math.max(yMax,y);					var o={x:x, value:y};					var attrs=cells[j].attributes;					for(var k=0; k<attrs.length; k++){						var attr=attrs.item(k);						var bIgnore=false;						for (var l=0; l<ignore.length; l++){							if (attr.nodeName.toLowerCase()==ignore[l]){								bIgnore=true;								break;							}						}						if(!bIgnore) o[attr.nodeName]=attr.nodeValue;					}					ds.add(o);				}			}		}		//	fix the axes		if(!bRangeX){			this.properties.axes.x.range={min:xMin, max:xMax};		}		if(!bRangeY){			this.properties.axes.y.range={min:yMin, max:yMax};		}		//	where to plot the axes		if (table.getAttribute("axisAt")){			var p=table.getAttribute("axisAt");			if (p.indexOf(",")>-1) p=p.split(",");			else p=p.split(" ");						//	x axis			if (!isNaN(parseFloat(p[0]))){				this.properties.axes.x.plotAt=parseFloat(p[0]);			} else if (p[0].toLowerCase()=="ymin"){				this.properties.axes.x.plotAt=this.properties.axes.y.range.min;			} else if (p[0].toLowerCase()=="ymax"){				this.properties.axes.x.plotAt=this.properties.axes.y.range.max;			}			// y axis			if (!isNaN(parseFloat(p[1]))){				this.properties.axes.y.plotAt=parseFloat(p[1]);			} else if (p[1].toLowerCase()=="xmin"){				this.properties.axes.y.plotAt=this.properties.axes.x.range.min;			} else if (p[1].toLowerCase()=="xmax"){				this.properties.axes.y.plotAt=this.properties.axes.x.range.max;			}		} else {			this.properties.axes.x.plotAt=this.properties.axes.y.range.min;			this.properties.axes.y.plotAt=this.properties.axes.x.range.min;		}		//	table values should be populated, now pop it off.		this.domNode.removeChild(table);		//	get the width and the height.//		this.properties.width=dojo.html.getInnerWidth(this.domNode);//		this.properties.height=dojo.html.getInnerHeight(this.domNode);		// ok, lets create the chart itself.		dojo.svg.g.suspend();				if(this.vectorNode) this.destroy();		this.vectorNode=document.createElementNS(dojo.svg.xmlns.svg, "svg");		this.vectorNode.setAttribute("width", this.properties.width);		this.vectorNode.setAttribute("height", this.properties.height);		//	set up the clip path for the plot area.		var defs = document.createElementNS(dojo.svg.xmlns.svg, "defs");		var clip = document.createElementNS(dojo.svg.xmlns.svg, "clipPath");		clip.setAttribute("id","plotClip"+this.widgetId);		var rect = document.createElementNS(dojo.svg.xmlns.svg, "rect");				rect.setAttribute("x", this.properties.padding.left);		rect.setAttribute("y", this.properties.padding.top);		rect.setAttribute("width", this.properties.width-this.properties.padding.left-this.properties.padding.right);		rect.setAttribute("height", this.properties.height-this.properties.padding.bottom-this.properties.padding.bottom);		clip.appendChild(rect);		defs.appendChild(clip);		this.vectorNode.appendChild(defs);		//	the plot background.		this.plotArea = document.createElementNS(dojo.svg.xmlns.svg, "g");		this.vectorNode.appendChild(this.plotArea);		var rect = document.createElementNS(dojo.svg.xmlns.svg, "rect");				rect.setAttribute("x", this.properties.padding.left);		rect.setAttribute("y", this.properties.padding.top);		rect.setAttribute("width", this.properties.width-this.properties.padding.left-this.properties.padding.right);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -