function dynamic_chart(title, tp, prefix, id, height, width, style, form, displayDiv) {

	this.type = tp;
	this.chart = new FusionCharts(style, id, width, height);

	// chart display variables
	this.outputVariables = new Array();
	this.colors = new Array();
		
	/**
	 * initialize the chart
	 */
	this.initialize = function() {
		this.chart.setDataXML(this.getChartXML());
	    this.chart.render(displayDiv); 	
	};
	
	/**
	 * redraw the chart
	 */
	this.redraw = function() {
		updateChartXML(id, this.getChartXML()) ;	
	};
  
	/*
	* build up chart xml from output variable values
	*/
	this.getChartXML = function() {	
		this.loadOutputVars();	
		var xmlString =  "<graph  formatNumberScale='0' decimalPrecision='0' caption='" + title + "' shownames='1' showvalues='1' numberPrefix='" + prefix +"' >";			
 	  	if (this.type == "StackedBar"){
 	  		
		 	xmlString += "<categories>"
				for (var j = 0; j<this.outputVariables.length; j++) {
				var item = this.outputVariables[j];
				xmlString += "<category name='" + item.label + "' />";
			}
		 	xmlString += "</categories>"
		 	
			for (var i = 0; i<this.outputVariables[0].multiValues.length; i++) {
				
				xmlString += "<dataset showValues='1' seriesName='" + this.outputVariables[0].multiValues[i].label + "' ";
				xmlString += " color='" + this.colors[i % this.colors.length] + "'>";
				
				for (var j = 0; j<this.outputVariables.length; j++) {
					xmlString += "<set value='" + this.outputVariables[j].multiValues[i].value+ "'/>";
				}
				xmlString += "</dataset>";
			}
 	  	}
 	  	else {
			for (var i = 0; i<this.outputVariables.length; i++) {
				var item = this.outputVariables[i];
				xmlString += "<set name='" + item.label + "' ";
				if ('Pie' == this.type){
					xmlString += " color='" + this.colors[i % this.colors.length] + "'";
				}
				else{
					xmlString += " color='" + this.colors[0] + "'";
				}
				xmlString += " value='" + item.value+ "'/>";
			}      	  
		}
		xmlString += "</graph>";
		return xmlString;	
	};
	
	/*
	 * load up the output variables
	 */
	this.loadOutputVars = function() {
	
		// get the current form value and set it as a js var
		for (var k=0; k<form.elements.length; k++) {
			input = form.elements[k];
			name = form.elements[k].name;
			if (name == "") continue;
			val = this.getInputValue(name);
			if (val == null || isNaN(val)) val = this.getDefault(name);
			var tempStr = "var " + name + "=" + val;	
			eval(tempStr);
		}
	  	
		// set up the xml values 
	  	for (var  i = 0; i<this.outputVariables.length; i++) {
 	  		var item = this.outputVariables[i];
 	  		
 	  		if (this.type == "StackedBar"){
	  			for (var  j = 0; j<item.multiValues.length; j++) {
 	  				var item1 = item.multiValues[j];
				
 	  				if (item1.zeroValue){
			 	  		item1.value = 0;
 	  				}
 	  				else
		 	  		if (item1.type == 'Input') {
		 	  			var v = eval(item1.name)*1.0;
		 	  			if (!isNaN(v)){
			 	  			item1.value = v.toFixed(0);
		 	  			}
		 	  		}
		 	  		else
		 	  		if (item1.expression != null && item1.expression != '') {
		 	  		// run the expression
			 	  		var v = eval(item1.expression)*1.0;
			 	  		if (!isNaN(v)){
				 	  		item1.value = v.toFixed(0);
			 	  		}
 	  				}
 	  			}
 	  		}
 	  		else{
	 	  		// set the value
	 	  		if (item.expression == null) {
		 	  		var v = eval(item.name)*1.0;
		 	  		if (!isNaN(v)){
		 	  			item.value = v.toFixed(0);
		 	  		}
	 	  			continue;
	 	  		}
	 	  		
	 	  		// run the expression
	 	  		var v = eval(item.expression)*1.0;
	 	  		if (!isNaN(v)){
		 	  		item.value = v.toFixed(0);
	 	  		}
			} 	  		
 	  	}
	  
	};

	/**	
	 * get the default value for the output
	 */
	this.getDefault = function(name) {
		for (var  i = 0; i<this.outputVariables.length; i++) {
			var item = this.outputVariables[i];
			if (item.name == name) return item.value;
		}
		return null;
	}

	/**
	 * get the input value
	 */	
	this.getInputValue = function(name) {
		widget = dijit.byId(name);
		if (!widget) return null;
		ret = widget.getValue();
		return ret == null || ret.length == 0 ? null : ret;
	}
	
}


