
//+---------------------------------------------------
//| 画图
//+---------------------------------------------------
function chart_pie(id, width, height, style, data)
{
	style["charttype"] = "pie";
	__chart_draw(id, width, height, style, data)
}

var __chart_default = {
	linecolor: "0x000000",
	font: {
		font: "Arial, Verdana, Helvetica, sans-serif, 宋体",
		fontsize: 12,
		fontcolor: "0x000000"
	}
};

function __chart_draw(id, width, height, style, data)
{
	var defaultstyle = __chart_default;

	var flashvars = {};
	var params = {
		quality: "high",
		wmode: "transparent"
	};

	if (typeof (style["default"]) == "undefined")
	{
		style["default"] = defaultstyle;
	}
	else
	{
		if (typeof (style["default"]["linecolor"]) == "undefined")
			style["default"]["linecolor"] = defaultstyle["linecolor"];
		if (typeof (style["default"]["font"]) == "undefined")
			style["default"]["font"] = defaultstyle["font"];
	}

	flashvars["style"] = __chart_param(style);
	flashvars["data"] = __chart_param(data);

	swfobject.embedSWF(
		"../flash/QlChart.swf", id, width, height,
		"9.0.0", "expressInstall.swf",
		flashvars, params
	);
}

function __chart_param(value)
{
	return '<?xml version=\'1.0\' encoding=\'utf-8\' ?>'
		+ ql_xml_objecttoxml("xml", value)
			.replace(/"/g, "'")
			.replace(/%/g, "%25")
			.replace(/&/g, "%27");
}

function ql_xml_objecttoxml(name, value)
{
	var xml = "";

	if (typeof (value) == "undefined" || value == null)
	{
		// do nothing
		xml = "<" + name + "></" + name + ">";
	}
	else
	{
		if (typeof (value) == "object" && value.constructor == Array)
		{
			for (i = 0; i < value.length; i++)
				xml += ql_xml_objecttoxml(name, value[i]);
			return xml;
		}
		else
		{
			xml = "<" + name + ">";
			if (typeof (value) == "object")
			{
				for (var p in value)
				{
					xml += ql_xml_objecttoxml(p, value[p]);
				}
			}
			else if (typeof (value) == "string")
			{
				xml += "<![CDATA[" + value + "]]>";
			}
			else
			{
				xml += "" + value;
			}
			xml += "</" + name + ">";
		}
	}

	return xml;
}