Ext和amcharts整合的扩展组件

此组件是一个flash报表的可视组件,直接继承自Ext.BoxComponent,封住了amcharts的一些固有逻辑,有一定的可重用性。



<!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>无标题文档</title>
<link rel="stylesheet" type="text/css" href="resources/css/ext-all.css"/>

<script type="text/javascript" src="ext-base-debug.js"></script>
<script type="text/javascript" src="ext-all-debug.js"></script>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
ReportComponent = Ext.extend(Ext.BoxComponent, {
	data_file: null,//报表数据来源
	settings_file: null,
	path: null,
	swfObject: null,
	swfUrl: null,
	id: Ext.id(),
	chartId: null,
	path: null,
    amType: null,
    width: 0,
    height: 0,
    autoLoad: false,//是否自动渲染flash
	//override
	onRender: function(ct, position) {
		ReportComponent.superclass.onRender.call(this, ct, position);
		this.ct = Ext.get(ct);
		this.init();
	},
	init: function() {
        this.swfObject = new SWFObject(this.swfUrl, this.amType, this.width, this.height, '8', '#FFFFFF');
	    var div = document.createElement('div');
	    this.chartId = 'chart' + this.id;
	    div.setAttribute('id', this.chartId);
	    this.ct.dom.appendChild(div);
	    this.el = Ext.get(div);
	    this.el.setSize(this.width, this.height);
	    this.el.set({
	    	width: this.width,
	    	height: this.height
	    });
	},
	//overrid
	afterRender: function() {
		ReportComponent.superclass.afterRender.apply(this, arguments);
		if (this.autoLoad) {
			this.loadReportData();
		}
	},
	loadReportData: function() {//加载数据并且显示chart
		this.addVariable('path', this.path);
		this.addVariable("settings_file", this.settings_file);  
		this.addVariable("data_file", this.data_file);  
		this.swfObject.write(this.chartId);
	},
	addVariable: function(key, value) {//需要额外配置时在loadReporData前调用此方法
		if (this.swfObject) {
			this.swfObject.addVariable(key, value);
		} else {
			this.init(); 
		}
	},
	setSwfObject: function(so) {
		this.swfObject = so;
	}
});
</script>
<script type="text/javascript">
Ext.onReady(function(){
   var r = new ReportComponent ({
       swfUrl: 'amcharts/flash/ampie.swf',
	   amType: 'ampie',
	   width: 500,
	   height: 400,
	   autoLoad: true,
	   settings_file: 'samples/PieAndDonut/Donut/settings.xml',
	   data_file: 'samples/PieAndDonut/Donut/data.txt'
   });
   r.render('r')
});
</script>
</head>
<body>
<div id="r"></div>
</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值