日期:2014-05-16  浏览次数:20432 次

smipleChart 简单图表类 javascript

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>smipleChart</title>
<style type="text/css">
.cc{
height:450px; width:800px; border:1px solid #999; position:relative; margin:20px;
}
</style>
</head>
<body>
<div id='t'></div>
<div id='t1'></div>
<div id='line' class="cc"></div>
<div id='area' class="cc"></div>
<div id='zhu' class="cc"></div>
<div id='zhu1' class="cc" style="height:600px;"></div>
<div id='segmentx' class="cc"></div>
<div id='segmenty' class="cc"></div>
<div id='pie' class="cc"></div>
<div id='pies' class="cc"></div>
<div id='vv' class="cc" style='height:300px; width:520px;'></div>
<script type="text/javascript">
(function(doc,undefined){
	var win       = this,
		uuuid     = -1,	
		hasSVG    = win.SVGAngle || doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"),
		isIE      = /msie/i.test(navigator.userAgent) && !win.opera,
		path      = hasSVG?'d':'path',
		seal      = hasSVG?'z':'e',
		math      = Math,
		mathRound = math.round,
		mathFloor = math.floor,
		mathCeil  = math.ceil,
		mathMax   = math.max,
		mathMin   = math.min,
		mathAbs   = math.abs,
		mathCos   = math.cos,
		mathSin   = math.sin,				
		M         = 'M',
		L         = 'L';

	win.$$ = function(Id){
		return document.getElementById(Id);
	};

	win.extend = function(){
		var target = arguments[0] || {}, i = 1, length = arguments.length, deep = true, options;
		if ( typeof target === "boolean" ) {
			deep = target;
			target = arguments[1] || {};
			i = 2;
		}
		if ( typeof target !== "object" && Object.prototype.toString.call(target)!="[object Function]")
			target = {};
		for(;i<length;i++){
			if ( (options = arguments[ i ]) != null )
				for(var name in options){
					var src = target[ name ], copy = options[ name ];
					if ( target === copy )
						continue;
					if ( deep && copy && typeof copy === "object" && !copy.nodeType ){
						target[ name ] = arguments.callee( deep, src || ( copy.length != null ? [ ] : { } ), copy );
					}   
					else if(copy !== undefined)
						target[ name ] = copy;                       
				}
	
		}
		return target;           
	};
	
	win.each =  function ( object, callback, args ) {  
		var name, i = 0, length = object.length;  
		if ( args ) {
			args = Array.prototype.slice.call(arguments).slice(2);
			if ( length === undefined ) {  
				for ( name in object )  
					if ( callback.apply( object[ name ],[name,object[ name ]].concat(args) ) === false )  
						break;  
			} else
				for ( ; i < length; i++)  
					if ( callback.apply( object[ i ],[i,object[ i ]].concat(args)) === false )   //
						break;  
		} else {     
			if ( length === undefined ) {  
				for ( name in object )  
					if ( callback.call( object[ name ], name, object[ name ] ) === false )  
						break;  
			} else
				for ( var value = object[0];  
					i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}  
		}  
		return object;  
	}; 
	
	win.contains = function(p,c){
		if(!p||!c)return false;
		if(p===c)return true;
		return isIE
			? p.contains(c)
			: p.compareDocumentPosition(c)==20
				? true
				: false;
	};
//---------------------------------------------------------------
	function processPoint( x ){
		return isIE ? ~~x.toFixed(0) : ~~x.toFixed(0) + 0.5;
	};
	function calTextLen(txt, cssStr){
		var span = doc.createElement('span');
		if(cssStr){
			typeof cssStr === 'string' 
				? span.sty