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

📄 chart.js

📁 dojo-0.3.0-ajax开 源 项 目
💻 JS
📖 第 1 页 / 共 2 页
字号:
		rect.setAttribute("height", this.properties.height-this.properties.padding.bottom-this.properties.padding.bottom);		rect.setAttribute("fill", "#fff");		this.plotArea.appendChild(rect);		//	data group		this.dataGroup = document.createElementNS(dojo.svg.xmlns.svg, "g");		this.dataGroup.setAttribute("style","clip-path:url(#plotClip"+this.widgetId+");");		this.plotArea.appendChild(this.dataGroup);		//	axis group		this.axisGroup = document.createElementNS(dojo.svg.xmlns.svg, "g");		this.plotArea.appendChild(this.axisGroup);		//	x axis		var stroke=1;		var line = document.createElementNS(dojo.svg.xmlns.svg, "line");		var y=dojo.widget.svg.Chart.Plotter.getY(this.properties.axes.x.plotAt, this);		line.setAttribute("y1", y);		line.setAttribute("y2", y);		line.setAttribute("x1",this.properties.padding.left-stroke);		line.setAttribute("x2",this.properties.width-this.properties.padding.right);		line.setAttribute("style","stroke:#000;stroke-width:"+stroke+";");		this.axisGroup.appendChild(line);				//	x axis units.		//	(min and max)		var textSize=10;		var text = document.createElementNS(dojo.svg.xmlns.svg, "text");		text.setAttribute("x", this.properties.padding.left);		text.setAttribute("y", this.properties.height-this.properties.padding.bottom+textSize+2);		text.setAttribute("style", "text-anchor:middle;font-size:"+textSize+"px;fill:#000;");		text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.x.range.min),2)));		this.axisGroup.appendChild(text);				var text = document.createElementNS(dojo.svg.xmlns.svg, "text");		text.setAttribute("x", this.properties.width-this.properties.padding.right-(textSize/2));		text.setAttribute("y", this.properties.height-this.properties.padding.bottom+textSize+2);		text.setAttribute("style", "text-anchor:middle;font-size:"+textSize+"px;fill:#000;");		text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.x.range.max),2)));		this.axisGroup.appendChild(text);					//	y axis		var line=document.createElementNS(dojo.svg.xmlns.svg, "line");		var x=dojo.widget.svg.Chart.Plotter.getX(this.properties.axes.y.plotAt, this);		line.setAttribute("x1", x);		line.setAttribute("x2", x);		line.setAttribute("y1", this.properties.padding.top);		line.setAttribute("y2", this.properties.height-this.properties.padding.bottom);		line.setAttribute("style", "stroke:#000;stroke-width:"+stroke+";");		this.axisGroup.appendChild(line);		//	y axis units		var text = document.createElementNS(dojo.svg.xmlns.svg, "text");		text.setAttribute("x", this.properties.padding.left-4);		text.setAttribute("y", this.properties.height-this.properties.padding.bottom);		text.setAttribute("style", "text-anchor:end;font-size:"+textSize+"px;fill:#000;");		text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.y.range.min),2)));		this.axisGroup.appendChild(text);				var text = document.createElementNS(dojo.svg.xmlns.svg, "text");		text.setAttribute("x", this.properties.padding.left-4);		text.setAttribute("y", this.properties.padding.top+(textSize/2));		text.setAttribute("style", "text-anchor:end;font-size:"+textSize+"px;fill:#000;");		text.appendChild(document.createTextNode(dojo.math.round(parseFloat(this.properties.axes.y.range.max),2)));		this.axisGroup.appendChild(text);			this.domNode.appendChild(this.vectorNode);		dojo.svg.g.resume();		//	this is last.		this.assignColors();		this._isInitialized=true;	},	destroy:function(){		while(this.domNode.childNodes.length>0){			this.domNode.removeChild(this.domNode.childNodes.item(0));		}		this.vectorNode=this.plotArea=this.dataGroup=this.axisGroup=null;	},	render:function(){		dojo.svg.g.suspend();				if (this.dataGroup){			while(this.dataGroup.childNodes.length>0){				this.dataGroup.removeChild(this.dataGroup.childNodes.item(0));			}		} else {			this.initialize();		}		//	the remove/append is an attempt to streamline the rendering, it's totally optional//		var p=this.dataGroup.parentNode;//		p.removeChild(this.dataGroup);		for(var i=0; i<this.series.length; i++){			dojo.widget.svg.Chart.Plotter.plot(this.series[i], this);		}//		p.appendChild(this.dataGroup);				dojo.svg.g.resume();	}});dojo.widget.svg.Chart.Plotter=new function(){	var _this=this;	var plotters = {};	var types=dojo.widget.Chart.PlotTypes;		this.getX=function(value, chart){		var v=parseFloat(value);		var min=chart.properties.axes.x.range.min;		var max=chart.properties.axes.x.range.max;		var ofst=0-min;		min+=ofst; max+=ofst; v+=ofst;		var xmin=chart.properties.padding.left;		var xmax=chart.properties.width-chart.properties.padding.right;		var x=(v*((xmax-xmin)/max))+xmin;		return x;	};	this.getY=function(value, chart){		var v=parseFloat(value);		var max=chart.properties.axes.y.range.max;		var min=chart.properties.axes.y.range.min;		var ofst=0;		if(min<0)ofst+=Math.abs(min);		min+=ofst; max+=ofst; v+=ofst;				var ymin=chart.properties.height-chart.properties.padding.bottom;		var ymax=chart.properties.padding.top;		var y=(((ymin-ymax)/(max-min))*(max-v))+ymax;		return y;	};	this.addPlotter=function(name, func){		plotters[name]=func;	};	this.plot=function(series, chart){		if (series.values.length==0) return;		if (series.plotType && plotters[series.plotType]){			return plotters[series.plotType](series, chart);		}		else if (chart.plotType && plotters[chart.plotType]){			return plotters[chart.plotType](series, chart);		}	};	//	plotting	plotters[types.Bar]=function(series, chart){		var space=1;		var lastW = 0;		for (var i=0; i<series.values.length; i++){			var x=_this.getX(series.values[i].x, chart);			var w;			if (i==series.values.length-1){				w=lastW;			} else{				w=_this.getX(series.values[i+1].x, chart)-x-space;				lastW=w;			}			x-=(w/2);			var yA=_this.getY(chart.properties.axes.x.plotAt, chart);			var y=_this.getY(series.values[i].value, chart);			var h=Math.abs(yA-y);			if (parseFloat(series.values[i].value)<chart.properties.axes.x.plotAt){				var oy=yA;				yA=y;				y=oy;			}			var bar=document.createElementNS(dojo.svg.xmlns.svg, "rect");			bar.setAttribute("fill", series.color);			bar.setAttribute("title", series.label + ": " + series.values[i].value);			bar.setAttribute("stroke-width", "0");			bar.setAttribute("x", x);			bar.setAttribute("y", y);			bar.setAttribute("width", w);			bar.setAttribute("height", h);			bar.setAttribute("fill-opacity", "0.9");			chart.dataGroup.appendChild(bar);		}	};	plotters[types.Line]=function(series, chart){		var tension=3;		var line = document.createElementNS(dojo.svg.xmlns.svg, "path");		line.setAttribute("fill", "none");		line.setAttribute("stroke", series.color);		line.setAttribute("stroke-width", "2");		line.setAttribute("stroke-opacity", "0.85");		line.setAttribute("title", series.label);		chart.dataGroup.appendChild(line);		var path = [];		for (var i=0; i<series.values.length; i++){			var x = _this.getX(series.values[i].x, chart)			var y = _this.getY(series.values[i].value, chart);			var dx = chart.properties.padding.left+1;			var dy = chart.properties.height-chart.properties.padding.bottom;			if (i>0){				dx=x-_this.getX(series.values[i-1].x, chart);				dy=_this.getY(series.values[i-1].value, chart);			}						if (i==0) path.push("M");			else {				path.push("C");				var cx=x-(tension-1)*(dx/tension);				path.push(cx+","+dy);				cx=x-(dx/tension);				path.push(cx+","+y);			}			path.push(x+","+y);		}		line.setAttribute("d", path.join(" "));	};	plotters[types.Scatter]=function(series, chart){		var r=7;		for (var i=0; i<series.values.length; i++){			var x=_this.getX(series.values[i].x, chart);			var y=_this.getY(series.values[i].value, chart);			var point = document.createElementNS(dojo.svg.xmlns.svg, "path");			point.setAttribute("fill", series.color);			point.setAttribute("stroke-width", "0");			point.setAttribute("title", series.label + ": " + series.values[i].value);			point.setAttribute("d",				"M " + x + "," + (y-r) + " " +				"Q " + x + "," + y + " " + (x+r) + "," + y + " " +				"Q " + x + "," + y + " " + x + "," + (y+r) + " " +				"Q " + x + "," + y + " " + (x-r) + "," + y + " " +				"Q " + x + "," + y + " " + x + "," + (y-r) + " " +				"Z"			);			chart.dataGroup.appendChild(point);		}	};	plotters[types.Bubble]=function(series, chart){		//	added param for series[n].value: size		var minR=1;				//	do this off the x axis?		var min=chart.properties.axes.x.range.min;		var max=chart.properties.axes.x.range.max;		var ofst=0-min;		min+=ofst; max+=ofst; v+=ofst;		var xmin=chart.properties.padding.left;		var xmax=chart.properties.width-chart.properties.padding.right;		var factor=(max-min)/(xmax-xmin)*25;				for (var i=0; i<series.values.length; i++){			var size = series.values[i].size;			if (isNaN(parseFloat(size))) size=minR;			var point=document.createElementNS(dojo.svg.xmlns.svg, "circle");			point.setAttribute("stroke-width", 0);			point.setAttribute("fill", series.color);			point.setAttribute("fill-opacity", "0.8");			point.setAttribute("r", (parseFloat(size)*factor)/2);			point.setAttribute("cx", _this.getX(series.values[i].x, chart));			point.setAttribute("cy", _this.getY(series.values[i].value, chart));			point.setAttribute("title", series.label + ": " + series.values[i].value + " (" + size + ")");			chart.dataGroup.appendChild(point);		}	};}();

⌨️ 快捷键说明

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