UU跑腿标准版

FusionCharts.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /**
  2. * FusionCharts Free: Flash Player detection and Chart embed
  3. *
  4. * Morphed from SWFObject (http://blog.deconcept.com/swfobject/) under MIT License:
  5. * http://www.opensource.org/licenses/mit-license.php
  6. *
  7. */
  8. if(typeof infosoftglobal == "undefined") var infosoftglobal = new Object();
  9. if(typeof infosoftglobal.FusionChartsUtil == "undefined") infosoftglobal.FusionChartsUtil = new Object();
  10. infosoftglobal.FusionCharts = function(swf, id, w, h, c){
  11. if (!document.getElementById) { return; }
  12. //Flag to see whether data has been set initially
  13. this.initialDataSet = false;
  14. //Create container objects
  15. this.params = new Object();
  16. this.variables = new Object();
  17. this.attributes = new Array();
  18. //Set attributes for the SWF
  19. if(swf) { this.setAttribute('swf', swf); }
  20. if(id) { this.setAttribute('id', id); }
  21. if(w) { this.setAttribute('width', w); }
  22. if(h) { this.setAttribute('height', h); }
  23. //Set background color
  24. if(c) { this.addParam('bgcolor', c); }
  25. //Set Quality
  26. this.addParam('quality', 'high');
  27. //Add scripting access parameter
  28. this.addParam('allowScriptAccess', 'always');
  29. this.addParam('swliveconnect', 'true');
  30. //Pass width and height to be appended as chartWidth and chartHeight
  31. this.addVariable('chartWidth', w);
  32. this.addVariable('chartHeight', h);
  33. }
  34. infosoftglobal.FusionCharts.prototype = {
  35. setAttribute: function(name, value){
  36. this.attributes[name] = value;
  37. },
  38. getAttribute: function(name){
  39. return this.attributes[name];
  40. },
  41. addParam: function(name, value){
  42. this.params[name] = value;
  43. },
  44. getParams: function(){
  45. return this.params;
  46. },
  47. addVariable: function(name, value){
  48. this.variables[name] = value;
  49. },
  50. getVariable: function(name){
  51. return this.variables[name];
  52. },
  53. getVariables: function(){
  54. return this.variables;
  55. },
  56. getVariablePairs: function(){
  57. var variablePairs = new Array();
  58. var key;
  59. var variables = this.getVariables();
  60. for(key in variables){
  61. variablePairs.push(key +"="+ variables[key]);
  62. }
  63. return variablePairs;
  64. },
  65. getSWFHTML: function() {
  66. var swfNode = "";
  67. if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
  68. // netscape plugin architecture
  69. swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" ';
  70. swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
  71. var params = this.getParams();
  72. for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
  73. var pairs = this.getVariablePairs().join("&");
  74. if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
  75. swfNode += '/>';
  76. } else { // PC IE
  77. swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
  78. swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
  79. var params = this.getParams();
  80. for(var key in params) {
  81. swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
  82. }
  83. var pairs = this.getVariablePairs().join("&");
  84. if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
  85. swfNode += "</object>";
  86. }
  87. return swfNode;
  88. },
  89. setDataURL: function(strDataURL){
  90. //This method sets the data URL for the chart.
  91. //If being set initially
  92. if (this.initialDataSet==false){
  93. this.addVariable('dataURL',strDataURL);
  94. //Update flag
  95. this.initialDataSet = true;
  96. }else{
  97. //Else do nothing as FusionCharts Free doesn't support dynamic
  98. //update of dataURL. It only supports update of dataXML.
  99. }
  100. },
  101. setDataXML: function(strDataXML){
  102. //If being set initially
  103. if (this.initialDataSet==false){
  104. //This method sets the data XML for the chart INITIALLY.
  105. this.addVariable('dataXML',strDataXML);
  106. //Update flag
  107. this.initialDataSet = true;
  108. }else{
  109. //In FusionCharts Free, we use updateChartXML method to update
  110. //the data of chart.
  111. }
  112. },
  113. render: function(elementId){
  114. var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
  115. n.innerHTML = this.getSWFHTML();
  116. return true;
  117. }
  118. }
  119. // ------------ Fix for Out of Memory Bug in IE in FP9 ---------------//
  120. /* Fix for video streaming bug */
  121. infosoftglobal.FusionChartsUtil.cleanupSWFs = function() {
  122. if (window.opera || !document.all) return;
  123. var objects = document.getElementsByTagName("OBJECT");
  124. for (var i=0; i < objects.length; i++) {
  125. objects[i].style.display = 'none';
  126. for (var x in objects[i]) {
  127. if (typeof objects[i][x] == 'function') {
  128. objects[i][x] = function(){};
  129. }
  130. }
  131. }
  132. }
  133. // Fixes bug in fp9
  134. infosoftglobal.FusionChartsUtil.prepUnload = function() {
  135. __flash_unloadHandler = function(){};
  136. __flash_savedUnloadHandler = function(){};
  137. if (typeof window.onunload == 'function') {
  138. var oldUnload = window.onunload;
  139. window.onunload = function() {
  140. infosoftglobal.FusionChartsUtil.cleanupSWFs();
  141. oldUnload();
  142. }
  143. } else {
  144. window.onunload = infosoftglobal.FusionChartsUtil.cleanupSWFs;
  145. }
  146. }
  147. if (typeof window.onbeforeunload == 'function') {
  148. var oldBeforeUnload = window.onbeforeunload;
  149. window.onbeforeunload = function() {
  150. infosoftglobal.FusionChartsUtil.prepUnload();
  151. oldBeforeUnload();
  152. }
  153. } else {
  154. window.onbeforeunload = infosoftglobal.FusionChartsUtil.prepUnload;
  155. }
  156. /* Add Array.push if needed (ie5) */
  157. if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}
  158. /* Function to return Flash Object from ID */
  159. infosoftglobal.FusionChartsUtil.getChartObject = function(id)
  160. {
  161. if (window.document[id]) {
  162. return window.document[id];
  163. }
  164. if (navigator.appName.indexOf("Microsoft Internet")==-1) {
  165. if (document.embeds && document.embeds[id])
  166. return document.embeds[id];
  167. } else {
  168. return document.getElementById(id);
  169. }
  170. }
  171. /*
  172. Function to update chart's data at client side
  173. */
  174. infosoftglobal.FusionChartsUtil.updateChartXML = function(chartId, strXML){
  175. //Get reference to chart object
  176. var chartObj = infosoftglobal.FusionChartsUtil.getChartObject(chartId);
  177. //Set dataURL to null
  178. chartObj.SetVariable("_root.dataURL","");
  179. //Set the flag
  180. chartObj.SetVariable("_root.isNewData","1");
  181. //Set the actual data
  182. chartObj.SetVariable("_root.newData",strXML);
  183. //Go to the required frame
  184. chartObj.TGotoLabel("/", "JavaScriptHandler");
  185. }
  186. /* Aliases for easy usage */
  187. var getChartFromId = infosoftglobal.FusionChartsUtil.getChartObject;
  188. var updateChartXML = infosoftglobal.FusionChartsUtil.updateChartXML;
  189. var FusionCharts = infosoftglobal.FusionCharts;