`
qq1988627
  • 浏览: 106020 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Ext 折线图

 
阅读更多
baseChart.js

Ext.ns('Ext.chart');
Ext.chart.BaseChart = Ext.extend(Ext.BoxComponent, {
	width:500,
	heigth:285,
	onRender : function(ct, position) {
		Ext.chart.BaseChart.superclass.onRender.call(this, ct, position);
		this.ct = Ext.get(ct);
		this.ct.position();
		this.ct.setStyle('overflow', 'hidden');
		this.createCanvas();
	},
	createCanvas : function(ct) {
		//if (!this.el) {
			var canvas = document.createElement("canvas");
			this.ct.dom.appendChild(canvas);
			this.el = Ext.get(canvas);
			if (Ext.isIE && G_vmlCanvasManager)
				this.el = Ext.get(G_vmlCanvasManager.initElement(canvas));
	//	}
		this.el = Ext.get(this.el);
		this.setCanvasSize(this.width, this.height);
		this.canvas = Ext.getDom(this.el);
		this.el.position('absolute', this.zIndex);
		this.ctx = this.getContext();
	},
	getContext : function() {
		return this.el.dom.getContext("2d");
	},
	
	setCanvasSize : function(w, h) {
		this.el.setSize(w, h);
		this.el.set( {
			width : w,
			height : h
		});
	}
});

BalloonTip.js

Ext.ns('Ext.ux');
Ext.ux.BalloonTip = Ext.extend(Ext.BoxComponent, {
	nodeWidth : 80,
	nodeHeight : 40,
	useCurveLine : true,
	useCurveRate : 0.15,

	yDetal : 0,
	xDetal : 0,

	xDetalRate : 40,
	bWHDetalRate : 20,
	xDetalBase : 10,
	btWidth : 10,
	btHeight : 10,
	tWidth : 15,
	tHeight : 15,
	radius : 5,
	rate : 1 / 2,
	midRate : 1 / 2,
	padRate : 1 / 10,

	angleDetal : 0,
	angleDetalStart : 0,

	textCls : '',
	data : [],
	color : '',
	direction : 't',
	constrain : true,
	autoRender : true,

	onRender : function(ct, position) {
		Ext.ux.BalloonTip.superclass.onRender.call(this, ct, position);
		this.initDirection = this.direction;
		this.ct = ct;
		if (this.text)
			this.addText(this.text);
		this.createCanvas();
	},
	getZIndex : function() {
		return parseInt(this.ct.getStyle("z-index"), 10) || 11000;
	},
	show : function(text, xy) {
		Ext.ux.BalloonTip.superclass.show.apply(this, arguments);

		if (text && text.isXType && text.isXType('panel')) {
			if (!text.rendered)
				text.renderTo(this.ct);
			else
				text.show();
			this.textEl = text;
		} else {
			this.addText(text);
		}
		this.adjustOuter(xy[0], xy[1]);
		this.draw();
		this.setXY(xy);
	},
	hide : function(text) {
		this.direction = this.initDirection;
		Ext.ux.BalloonTip.superclass.hide.apply(this, arguments);
		if (this.textEl) {
			this.textEl.dom.innerHTML = "";
			this.textEl.setLeftTop(-10000, -10000);
			this.el.setLeftTop(-10000, -10000);
		}
	},
	createCanvas : function() {
		//if (!this.el) {
			var canvas = document.createElement("canvas");
			this.ct.dom.appendChild(canvas);
			this.el = Ext.get(canvas);
			if (Ext.isIE && G_vmlCanvasManager)
				this.el = Ext.get(G_vmlCanvasManager.initElement(canvas));
		//}
		this.el = Ext.get(this.el);
		this.setCanvasSize(this.width, this.height);
		this.canvas = Ext.getDom(this.el);
		this.el.position('absolute', this.zIndex || this.getZIndex() + 2);
		this.ctx = this.getContext();
	},
	getContext : function() {
		return this.el.dom.getContext("2d");
	},
	constrainXY : function(x1, y1) {
		if (this.constrain) {
			var constrainEl = Ext.get(this.constrainCt || document);
			var cbox = constrainEl.getBox(), tbox = this.el.getBox();
			var ox = tbox.x - cbox.x, oy = tbox.y - cbox.y;
			var or = tbox.right - cbox.right, ob = tbox.bottom - cbox.bottom;
			var ow = tbox.width - cbox.width, oh = tbox.height - cbox.height;
			switch (this.direction) {
				case 't' :
					ox < 0 ? x1 = x1 - ox : "";
					or > 0 ? x1 = x1 - or : "";
					if (oh < 0) {
						oy < 0 ? y1 = y1 - oy : '';
						ob > 0 ? this.changeDirection('b', x1, y1) : '';
					}
					break;
				case 'b' :
					ox < 0 ? x1 = x1 - ox : "";
					or > 0 ? x1 = x1 - or : "";
					if (oh < 0) {
						ob > 0 ? y1 = y1 - ob : "";
						oy < 0 ? this.changeDirection('t', x1, y1) : '';
					}
					break;
				case 'l' :
					ob > 0 ? y1 = y1 - ob : "";
					oy < 0 ? y1 = y1 - oy : "";
					if (ow < 0) {
						ox < 0 ? x1 = x1 - ox : "";
						or > 0 ? this.changeDirection('r', x1, y1) : '';
					}
					break;
				case 'r' :
					ob > 0 ? y1 = y1 - ob : "";
					oy < 0 ? y1 = y1 - oy : "";
					if (ow < 0) {
						or > 0 ? x1 = x1 - or : "";
						ox < 0 ? this.changeDirection('l', x1, y1) : '';
					}
					break;
			}
			x1 = parseInt(x1), y1 = parseInt(y1);
			x1 < 0 ? x1 = 0 : "";
			y1 < 0 ? y1 = 0 : "";
			//alert(x1,y1);
			this.setPagePosition(x1, y1);
		}
	},
	changeDirection : function(direction, x, y) {
		this.direction = direction;
		this.adjustOuter(x, y);
		this.draw();
	},
	addText : function(text) {
		if (!this.textEl) {
			this.textEl = Ext.get(this.ct).createChild();
			this.textEl.addClass(this.textCls);
		}
		Ext.DomHelper.overwrite(this.textEl, text);

		var size = Ext.util.TextMetrics.measure(this.textEl, text);
		this.nodeWidth = size.width + 10;
		this.nodeHeight = size.height + 10;
		this.textEl.setSize(this.nodeWidth, this.nodeHeight);
		this.textEl.position('absolute', this.zIndexText || this.getZIndex()
				+ 3);
	},
	afterRender : function() {
		Ext.ux.BalloonTip.superclass.afterRender.apply(this, arguments);
	},
	setXY : function(xy) {
		this.setPagePosition(xy[0], xy[1]);
		this.constrainXY(xy[0], xy[1]);

	},
	setCanvasSize : function(w, h) {
		var width, height;
		switch (this.direction) {
			case 't' :
			case 'b' :
				width = this.nodeWidth + this.angleDetal || 0;
				height = this.nodeHeight + this.tHeight + this.yDetal;
				break;
			case 'l' :
			case 'r' :
				width = this.nodeWidth + this.tHeight + this.yDetal + 1;
				height = this.nodeHeight + this.angleDetal || 0;
				break;
		}
		this.el.setSize(width, height);
		this.el.set( {
			width : width,
			height : height
		});
		this.width = width;
		this.height = height;
	},
	between : function(x, min, max) {
		if (x < min)
			x = min;
		if (x > max)
			x = max;
		return x;
	},
	adjustStart : function() {
		var x = this.tWidth + this.yDetal, y = this.tHeight + this.yDetal;
		switch (this.direction) {
			case 't' :
				x = 0 + this.angleDetalStart || 0;
				break;
			case 'b' :
				x = 0 + this.angleDetalStart || 0, y = 0;
				break;
			case 'l' :
				x = y;
				y = 0 + this.angleDetalStart || 0;
				break;
			case 'r' :
				x = y;
				y = 0;
				break;
		}
		return {
			x : x,
			y : y
		};
	},
	calDetal : function() {
		var midRate = (this.rate - 0.5), absMidRate = Math.abs(midRate);
		var bWHDetal = absMidRate * this.bWHDetalRate;
		this.xDetal = midRate * this.xDetalRate;
		this.tWidth = this.btWidth + bWHDetal;
		this.tHeight = this.btHeight + bWHDetal;
		if (this.angleToCurve == false)
			this.useCurveLine = false;
		else
			this.useCurveLine = absMidRate < this.useCurveRate ? false : true;

	},
	calAngleDetal : function(w) {
		var o = this.radius + this.offsetLen + this.tWidth * this.midRate
				+ this.xDetal;
		nwh = (w == 'w') ? this.nodeWidth : this.nodeHeight;
		if (o < 0) {
			this.angleDetal = Math.abs(o);
			this.angleDetalStart = Math.abs(o);
		} else if (o - nwh > 0)
			this.angleDetal = o - nwh;
		else {
			this.angleDetal = 0;
			this.angleDetalStart = 0;
		}
	},
	offset : function(wh, r, rate) {
		return (wh - 2 * r) * rate;
	},
	calOffsetLen : function(w) {
		var nwh = (w == "w") ? this.nodeWidth : this.nodeHeight;
		var len = (nwh - 2 * this.radius) * this.rate;
		var minLen = nwh * this.padRate;
		var maxLen = nwh - 2 * this.radius - this.tWidth - minLen;
		this.offsetLen = this.between(len, minLen, maxLen);
	},
	calRate : function(x, y, w) {
		if (this.constrainCt) {
			var ctBox = Ext.get(this.constrainCt).getBox();
			var v = (w == "w") ? (x - ctBox.x) / ctBox.width : (y - ctBox.y)
					/ ctBox.height;
			this.rate = this.between(v, 0, 1);
		}
	},
	adjustOuter : function(x, y) {
		if (this.constrain) {
			switch (this.direction) {
				case 't' :
				case 'b' :
					var flag = 'w';
					break;
				case 'l' :
				case 'r' :
					var flag = 'h';
			}
			this.calRate(x, y, flag);
			this.calDetal();
			this.calOffsetLen(flag);
			this.calAngleDetal(flag);
		}
	},
	draw : function() {
		this.setCanvasSize();
		var len = this.offsetLen || 0, r = this.radius;
		var tw = this.tWidth, th = this.tHeight, nw = this.nodeWidth, nh = this.nodeHeight;
		var xy = this.adjustStart(), x = xy.x, y = xy.y;

		this.ctx.strokeStyle = this.bdcolor || '#000000';
		this.ctx.lineWidth = this.lineWidth || 1;
		this.ctx.fillStyle = this.bgcolor || 'white';
		this.ctx.clearRect(0, 0, this.width, this.height);
		this.ctx.beginPath();
		this.ctx.moveTo(x, y + r);
		this.ctx.quadraticCurveTo(x, y, x + r, y);

		this.drawAngle('t', len, x, y, r, tw, th);
		this.ctx.lineTo(x + nw - 2 * r, y);
		this.ctx.quadraticCurveTo(x + nw, y, x + nw, y + r);
		this.drawAngle('r', len, x, y, r, tw, th);

		this.ctx.lineTo(x + nw, y + nh - 2 * r);
		this.ctx.quadraticCurveTo(x + nw, y + nh, x + nw - r, y + nh);
		this.drawAngle('b', len, x, y, r, tw, th);

		this.ctx.lineTo(x + r, y + nh);
		this.ctx.quadraticCurveTo(x, y + nh, x, y + nh - r);
		this.drawAngle('l', len, x, y, r, tw, th);

		this.ctx.lineTo(x, y + r);
		this.ctx.fill();
		this.ctx.stroke();
	},

	onDestroy : function() {
		if (this.textEl)
			this.textEl.remove();
	},
	drawAngle : function(direction, len, x, y, r, tw, th) {
		var x1, y1, x2, y2, x3, y3, x4, y4, x5, y5;
		if (this.direction != direction)
			return;
		switch (this.direction) {
			case 't' :
				x1 = x + r + len, y1 = y;
				x2 = x1 + tw * this.midRate + this.xDetal;
				y2 = y1 - th - this.yDetal;
				x3 = x1 + tw, y3 = y1;
				break;
			case 'b' :
				x3 = x + r + len, y3 = y + this.nodeHeight;
				x1 = x3 + tw, y1 = y3;
				x2 = x3 + tw * this.midRate + this.xDetal;
				y2 = y3 + th + this.yDetal;
				break;
			case 'l' :
				x3 = x, y3 = y + r + len;
				x1 = x3, y1 = y3 + tw;
				x2 = x3 - th - this.yDetal;
				y2 = y3 + tw * this.midRate + this.xDetal;
				break;
			case 'r' :
				x1 = x + this.nodeWidth, y1 = y + r + len;
				x2 = x1 + th + this.yDetal;
				y2 = y1 + tw * this.midRate + this.xDetal;
				x3 = x1, y3 = y1 + tw;
		}

		this.ctx.lineTo(x1, y1);
		if (this.useCurveLine) {
			x4 = x1, y4 = y2;
			x5 = x3, y5 = y2;
			this.ctx.quadraticCurveTo(x4, y4, x2, y2);
			this.ctx.quadraticCurveTo(x5, y5, x3, y3);
		} else {
			this.ctx.lineTo(x2, y2);
			this.ctx.lineTo(x3, y3);
		}
	},

	realignText : function() {
		var xy = this.adjustStart(), x = xy.x, y = xy.y;
		x = this.x1 + x, y = this.y1 + y;
		this.textEl.setLeftTop(x, y);
	},
	setPagePosition : function(x2, y2) {
		Ext.ux.BalloonTip.superclass.setPagePosition.apply(this, arguments);
		this.realignText();
	},
	adjustPosition : function(x1, y1) {
		var detal = this.radius + this.offsetLen + this.tWidth * this.midRate
				+ this.xDetal + this.angleDetalStart;
		switch (this.direction) {
			case 't' :
				x = x1 - detal;
				y = y1;
				break;
			case 'b' :
				x = x1 - detal;
				y = y1 - this.height;
				break;
			case 'l' :
				x = x1;
				y = y1 - detal;
				break;
			case 'r' :
				x = x1 - this.width;
				y = y1 - detal;
		}
		this.x1 = x;
		this.y1 = y;

		return {
			x : x,
			y : y
		};
	}
});

// 背景色与背景图
// 采用panel,window做为内容
// 计算约束
 
  • 大小: 23 KB
分享到:
评论

相关推荐

    EXT创建动态的折线图

    在这个场景下,"EXT创建动态的折线图"指的是利用EXT库来动态地展示数据变化的过程,这种图表常用于监控实时数据或者分析历史趋势。 动态折线图的核心在于数据的实时更新和图表的平滑刷新。EXT提供了一个名为`Ext....

    ExtJS制作折线图

    在给定的"ExtJS 制作折线图"主题中,我们将深入探讨如何使用ExtJS 的lineChart组件来创建动态、交互式的折线图。 首先,让我们了解什么是折线图。折线图是一种统计图表,通过连接一系列数据点来显示数值的变化趋势...

    ext4.0生成图形报表(柱形、折线、饼状)

    对于折线图,我们同样使用`Ext.chart.Chart`,但设置`series.type`为'line'。饼状图则需要设置`series.type`为'pie',并指定`donut`属性来控制饼图的内径大小。 在处理数据时,EXT4.0支持多种数据源,可以是JSON...

    ExtJs双折线图

    在这个特定的场景中,"ExtJs双折线图"是指使用Ext Js库来创建具有两组数据的折线图表。这种图表类型在数据分析和可视化中非常常见,可以用来比较两个变量随时间的变化趋势。 首先,创建一个双折线图需要对Ext Js的...

    EXtjs 统计图 饼图 直方图 和折线图

    在ExtJS中,使用`Ext.chart.Chart`和`Ext.chart.series.Line`系列配置可以创建折线图。你可以设置线的样式、点的标记,以及时间轴的格式化。以下是一个折线图的例子: ```javascript Ext.application({ name: 'App...

    EXT安装包4.2.1-1

    4. **强大的图表库**:EXT包含一个完整的图表组件,可以生成各种统计和数据分析图表,如折线图、柱状图、饼图等。 5. **触摸支持**:EXT4.2.1优化了对触摸设备的支持,使得在平板电脑和智能手机上也能流畅操作。 6. ...

    extjs4图表绘制之折线图实现方法分析

    在EXTJS4中,创建折线图是一种常用的数据可视化方式,可以帮助用户直观地理解数据变化趋势。本实例主要讲解如何利用EXTJS4的图表功能来实现动态数据的折线图展示,包括从后端获取数据并展示在图表上,以及查询每年...

    ext 3.3 中文 chm

    8. 图表(Charts):EXT 3.3的图表组件,如何创建各种统计图表,如柱状图、折线图等。 9. 性能优化(Performance Optimization):提供了一些提高EXT 3.3应用程序性能的技巧和策略。 10. API参考(API Reference):...

    Ext4.1.0Doc_SUN.zip

    6. **图表和可视化**:EXT的图表组件在4.1版本中得到了增强,支持多种图表类型,如折线图、柱状图、饼图等,便于进行数据可视化。 7. **主题和皮肤**:EXT4.1提供了多种预定义的主题,如gray、silver、triton等,...

    ext3.0中文API

    Charts是EXT3.0中的一个亮点,它支持各种类型的图表,如柱状图、折线图、饼图和散点图。通过API,开发者可以自定义图表的颜色、样式、数据源和交互行为,为数据可视化提供强大的工具。 除此之外,EXT3.0还包括了...

    Ext手册中文pdf版本

    5. **图表组件**:Ext的图表组件支持创建各种复杂的统计图表,如折线图、柱状图、饼图等,有助于数据可视化。 6. **触摸支持**:Ext Touch是针对移动设备的版本,提供了一套专为触摸屏优化的组件和API,使开发者...

    EXT ,EXT.chm,ext中文

    4. **高级图表**:EXT提供了多种图表类型,如折线图、柱状图、饼图等,可用于数据可视化。 5. **触摸支持**:EXT Touch是EXT的移动版本,专门用于开发触屏设备上的应用程序。 6. **AJAX通信**:EXT内置了AJAX功能...

    Ext图形报表

    这些图表包括折线图、柱状图、饼图、散点图、面积图等,能够满足大多数数据可视化的需要。通过这些图表,用户可以直观地理解大量复杂数据。 在实现图形报表时,首先需要了解Ext.chart.Chart组件,它是ExtJS图表的...

    ext 3.0 中文API

    6. **Charts**:EXT 3.0 提供了图表组件,支持各种类型的图表,如柱状图、折线图、饼图等,可用于数据可视化。 7. **Ajax**:EXT内建的Ajax模块提供了一种简便的方式与服务器进行异步通信,可以处理JSON、XML等多种...

    Ext JS学习资料

    4. **强大的图表功能**:内置的图表库支持多种图表类型,如折线图、柱状图等。 5. **主题定制**:用户可以轻松地定制界面样式,满足个性化需求。 6. **移动设备兼容**:虽然主要针对桌面端,但Ext JS 4也考虑到了...

    Ext 3.0 中文文档

    8. **图表功能**:如果文档包含这部分内容,会介绍Ext的图表组件,如柱状图、折线图、饼图等,以及如何创建和定制图表。 9. **国际化与本地化**:讨论如何在Ext 3.0应用中实现多语言支持。 10. **最佳实践和性能...

    Ext 中文帮助文档

    12. **图表组件**:提供了各种图表类型,如折线图、柱状图、饼图等,用于数据可视化。 13. **触摸支持**:Ext Touch是针对移动设备优化的版本,支持触屏操作,可以开发响应式的跨平台应用。 14. **国际化支持**:...

    EXT examples

    4. **图表组件**:EXT提供了一系列的图表组件,包括折线图、柱状图、饼图等,适用于数据分析和可视化。你可以通过示例了解如何加载数据、配置图例、轴线和数据系列。 5. **Ajax和远程数据交互**:EXT通过Store组件...

    Ext JS 4 Architecture

    Ext JS 4中的图表组件提供了创建复杂数据可视化的能力,支持多种图表类型,如条形图、折线图、饼图等。动画方面,Ext JS 4提供了一套流畅的动画引擎,可以增强用户体验,让界面变化显得平滑自然。 10. **扩展性...

Global site tag (gtag.js) - Google Analytics