最近在项目中要用到图表,fusioncharts比较漂亮,于是下载了个破解版的,但在实际用的过程中,每打开一个fusioncharts,内存都要增长,暂时用下面方法解决下
var myChart1 = null;
var myChart2 = null;
var myChart3 = null;
var combo = null;
var panel = null;
function showChart()
{
combo = new Ext.form.ComboBox({
fieldLabel: '图表展示类型',
id: 'combo',
triggerAction:'all',
width: 110,
store: new Ext.data.SimpleStore({
fields:['value','text'],
data: [
['1','柱状图'],
['2','比例图'],
['3','趋势图']
]
}),
displayField:'text',
valueField:'value',
mode:'local',
emptyText: '请选择'
})
panel = new Ext.Panel({
items: [combo],
width: 800,
height: 500,
html: "<div id = \"showChart\"></div>"
});
var win = new Ext.Window({
renderTo: 'showWin',
width: 800,
height: document.documentElement.clientHeight-50,
x:200,
y:10,
closable: false,
buttonAlign:'center',
items:[panel],
buttons:[{text:'日'},{text:'周'},{text:'月'},{text:'年'},{
text:'关闭',
handler:function(){
win.close();
win = null;
combo = null;
panel = null;
}
}]
});
win.show();
var chartXMLData = "<chart caption=\"用电对比情况\" XAxisName=\"\" palette=\"2\" animation=\"1\" formatNumberScale=\"0\" numberPrefix=\"\" showValues=\"0\" numDivLines=\"4\" legendPosition=\"BOTTOM\">"+
"<categories><category label=\"一月\" /><category label=\"二月\" /><category label=\"三月\" /><category label=\"四月\" /><category label=\"五月\" /><category label=\"六月\" /></categories>"+
"<dataset seriesName=\"杭州三花研究院\"><set value=\"5810.75\" /><set value=\"12517.75\" /><set value=\"4183.75\" /><set value=\"3510.5\" /><set value=\"5789.25\" /><set value=\"4421\" /></dataset>"+
"<dataset seriesName=\"伊萨卡国际城\"><set value=\"14706.43\" /><set value=\"3965.17\" /><set value=\"25377.86\" /><set value=\"4203.66\" /><set value=\"26680.88\" /><set value=\"48\" /></dataset>"+
"<styles><definition><style type=\"font\" name=\"CaptionFont\" color=\"666666\" size=\"15\" /><style type=\"font\" name=\"SubCaptionFont\" bold=\"0\" /></definition><application><apply toObject=\"caption\" styles=\"CaptionFont\" /><apply toObject=\"SubCaption\" styles=\"SubCaptionFont\" /></application></styles></chart>";
if(FusionCharts.items["1"] == null)
{
myChart1 = new FusionCharts("../../FusionCharts/Charts/MSColumn3D.swf", "1", "780", "450", "0", "1");
}
myChart1.setXMLData(chartXMLData);
myChart1.render("showChart");
combo.on("select",function(comboBox){
if(comboBox.getValue() == 1)
{
if(FusionCharts.items["1"] == null)
{
myChart1 = new FusionCharts("../../FusionCharts/Charts/MSColumn3D.swf", "1", "780", "450", "0", "1");
}
myChart1.setXMLData(chartXMLData);
myChart1.render("showChart");
}
else if(comboBox.getValue() == 2)
{
if(FusionCharts.items["2"] == null)
{
myChart2 = new FusionCharts("../../FusionCharts/Charts/Pie3D.swf", "2", "780", "450", "0", "1");
}
var chartXMLData2 = "<chart caption='用电对比情况' subCaption=''>";
chartXMLData2 += "<set label='杭州三花研究院' value='" + 543556 + "' />";
chartXMLData2 += "<set label='伊萨卡国际城' value='" + 767523 + "' />";
chartXMLData2 += "</chart>";
myChart2.setXMLData(chartXMLData2);
myChart2.render("showChart");
}
else
{
if(FusionCharts.items["3"] == null)
{
myChart3 = new FusionCharts("../../FusionCharts/Charts/MSLine.swf", "3", "780", "450", "0", "1");
}
myChart3.setXMLData(chartXMLData);
myChart3.render("showChart");
}
});