]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/SugarCharts/Jit/js/sugarCharts.js
Release 6.2.0beta4
[Github/sugarcrm.git] / jssource / src_files / include / SugarCharts / Jit / js / sugarCharts.js
1 /*********************************************************************************
2  * SugarCRM is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by the
7  * Free Software Foundation with the addition of the following permission added
8  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
15  * details.
16  * 
17  * You should have received a copy of the GNU Affero General Public License along with
18  * this program; if not, see http://www.gnu.org/licenses or write to the Free
19  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  * 
22  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
24  * 
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  * 
29  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30  * these Appropriate Legal Notices must retain the display of the "Powered by
31  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32  * technical reasons, the Appropriate Legal Notices must display the words
33  * "Powered by SugarCRM".
34  ********************************************************************************/
35
36
37
38
39 function loadSugarChart (chartId,jsonFilename,css,chartConfig) {
40
41                                 var labelType, useGradients, nativeTextSupport, animate;
42                                 (function() {
43                                   var ua = navigator.userAgent,
44                                           typeOfCanvas = typeof HTMLCanvasElement,
45                                           nativeCanvasSupport = (typeOfCanvas == 'object' || typeOfCanvas == 'function'),
46                                           textSupport = nativeCanvasSupport 
47                                                 && (typeof document.createElement('canvas').getContext('2d').fillText == 'function');
48                                   labelType = 'Native';
49                                   nativeTextSupport = labelType == 'Native';
50                                   useGradients = nativeCanvasSupport;
51                                   animate = false;
52                                 })();
53                                 
54                         
55                         switch(chartConfig["chartType"]) {
56                         case "barChart":
57                                 var handleFailure = function(o){
58                                 alert('fail');
59                                         if(o.responseText !== undefined){
60                                                 alert('failed');
61                                         }
62                                 }       
63                                 var handleSuccess = function(o){
64
65                                         if(o.responseText !== undefined && o.responseText != "No Data"){        
66                                         var json = eval('('+o.responseText+')');
67
68                                 var properties = $jit.util.splat(json.properties)[0];   
69                                 var marginBottom = (chartConfig["orientation"] == 'vertical' && json.values.length > 8) ? 20*4 : 20;
70                                 //init BarChart
71                                 var barChart = new $jit.BarChart({
72                                   //id of the visualization container
73                                   injectInto: chartId,
74                                   //whether to add animations
75                                   animate: false,
76                                   nodeCount: json.values.length,
77                                   renderBackground: chartConfig['imageExportType'] == "jpg" ? true: false,
78                                   backgroundColor: 'rgb(255,255,255)',
79                                   colorStop1: 'rgba(255,255,255,.8)',
80                                   colorStop2: 'rgba(255,255,255,0)',
81                                   shadow: {
82                                      enable: true,
83                                      size: 2    
84                                   },
85                                   //horizontal or vertical barcharts
86                                   orientation: chartConfig["orientation"],
87                                   hoveredColor: false,
88                                   Title: {
89                                         text: properties['title'],
90                                         size: 16,
91                                         color: '#444444',
92                                         offset: 20
93                                   },
94                                   Subtitle: {
95                                         text: properties['subtitle'],
96                                         size: 11,
97                                         color: css["color"],
98                                         offset: 20
99                                   },
100                                   Ticks: {
101                                         enable: true,
102                                         color: css["gridLineColor"]
103                                   },
104                                   //bars separation
105                                   barsOffset: (chartConfig["orientation"] == "vertical") ? 30 : 20,
106                                   //visualization offset
107                                   Margin: {
108                                         top:20,
109                                         left: 30,
110                                         right: 20,
111                                         bottom: marginBottom
112                                   },
113                                   ScrollNote: {
114                                         text: (chartConfig["scroll"] && SUGAR.util.isTouchScreen()) ? "Use two fingers to scroll" : "",
115                                         size: 12
116                                   },
117                                   Events: {
118                                         enable: true,
119                                         onClick: function(node) {  
120                                         if(!node || SUGAR.util.isTouchScreen()) return;  
121                                         if(node.link == 'undefined' || node.link == '') return;
122                                         window.location.href=node.link;
123                                         }
124                                   },
125                                   //labels offset position
126                                   labelOffset: 5,
127                                   //bars style
128                                   type: useGradients? chartConfig["barType"]+':gradient' : chartConfig["barType"],
129                                   //whether to show the aggregation of the values
130                                   showAggregates:true,
131                                   //whether to show the labels for the bars
132                                   showLabels:true,
133                                   //labels style
134                                   Label: {
135                                         type: labelType, //Native or HTML
136                                         size: 12,
137                                         family: css["font-family"],
138                                         color: css["color"],
139                                         colorAlt: "#ffffff"
140                                   },
141                                   //add tooltips
142                                   Tips: {
143                                         enable: true,
144                                         onShow: function(tip, elem) {
145                                           if(elem.link != 'undefined' && elem.link != '') {
146                                                 drillDown = (SUGAR.util.isTouchScreen()) ? "<br><a href='"+ elem.link +"'>Click to drilldown</a>" : "<br>Click to drilldown";
147                                           } else {
148                                                 drillDown = "";
149                                           }
150
151                                           if(elem.valuelabel != 'undefined' && elem.valuelabel != undefined && elem.valuelabel != '') {
152                                                 value = "elem.valuelabel";
153                                           } else {
154                                                 value = "elem.value";
155                                           }
156                                           eval("tip.innerHTML = '<b>' + elem."+chartConfig["tip"]+" + '</b>: ' + "+value+" + ' - ' + elem.percentage + '%' + drillDown");
157                                         }
158                                   }
159                                 });
160                                 //load JSON data.
161                                 barChart.loadJSON(json);
162                                 //end
163                                 
164                                 /*
165                                 var list = $jit.id('id-list'),
166                                         button = $jit.id('update'),
167                                         orn = $jit.id('switch-orientation');
168                                 //update json on click 'Update Data'
169                                 $jit.util.addEvent(button, 'click', function() {
170                                   var util = $jit.util;
171                                   if(util.hasClass(button, 'gray')) return;
172                                   util.removeClass(button, 'white');
173                                   util.addClass(button, 'gray');
174                                   barChart.updateJSON(json2);
175                                 });
176                                 */
177                                 //dynamically add legend to list
178                                 var list = $jit.id('legend'+chartId);
179                                 var legend = barChart.getLegend(),
180                                         cols = (typeof SUGAR == 'undefined' || typeof SUGAR.mySugar == 'undefined') ? 8 : 4,
181                                         rows = Math.ceil(legend["name"].length/cols),
182                                         table = "<table cellpadding='0' cellspacing='0' align='left'>";
183                                 var j = 0;
184                                 for(i=0;i<rows;i++) {
185                                         table += "<tr>"; 
186                                         for(td=0;td<cols;td++) {
187                                                 
188                                                 table += '<td nowrap>';
189                                                 if(legend["name"][j] != undefined) {
190                                                         table += '<div class=\'query-color\' style=\'background-color:'
191                                                           + legend["color"][j] +'\'>&nbsp;</div>' + legend["name"][j];
192                                                 }
193                                                   
194                                                 table += '</td>';
195                                                 j++;
196                                                 }
197                                         table += "</tr>"; 
198                                 }
199                                 
200                                         table += "</table>";
201                                 list.innerHTML = table;
202                                 
203                                 
204                                 //save canvas to image for pdf consumption
205                                 $jit.util.saveImageTest(chartId,jsonFilename,chartConfig["imageExportType"]);
206                                 
207                                 
208                                         }
209                                 }
210                                                 
211                                 var callback =
212                                 {
213                                   success:handleSuccess,
214                                   failure:handleFailure,
215                                   argument: { foo:'foo', bar:''}
216                                 };
217                                 
218                                 var request = YAHOO.util.Connect.asyncRequest('GET', jsonFilename + "?r=" + new Date().getTime(), callback);
219                                 break;
220                                 
221                         case "lineChart":
222                                 var handleFailure = function(o){
223                                 alert('fail');
224                                         if(o.responseText !== undefined){
225                                                 alert('failed');
226                                         }
227                                 }       
228                                 var handleSuccess = function(o){
229
230                                         if(o.responseText !== undefined && o.responseText != "No Data"){        
231                                         var json = eval('('+o.responseText+')');
232
233                                 var properties = $jit.util.splat(json.properties)[0];   
234                                 //init Linecahrt
235                                 var lineChart = new $jit.LineChart({
236                                   //id of the visualization container
237                                   injectInto: chartId,
238                                   //whether to add animations
239                                   animate: false,
240                                   renderBackground: chartConfig['imageExportType'] == "jpg" ? true: false,
241                                   backgroundColor: 'rgb(255,255,255)',
242                                   colorStop1: 'rgba(255,255,255,.8)',
243                                   colorStop2: 'rgba(255,255,255,0)',
244                                   selectOnHover: false,
245                                   Title: {
246                                         text: properties['title'],
247                                         size: 16,
248                                         color: '#444444',
249                                         offset: 20
250                                   },
251                                   Subtitle: {
252                                         text: properties['subtitle'],
253                                         size: 11,
254                                         color: css["color"],
255                                         offset: 20
256                                   },
257                                   Ticks: {
258                                         enable: true,
259                                         color: css["gridLineColor"]
260                                   },
261                                   //visualization offset
262                                   Margin: {
263                                         top:20,
264                                         left: 40,
265                                         right: 40,
266                                         bottom: 20
267                                   },
268                                   Events: {
269                                         enable: true,
270                                         onClick: function(node) {  
271                                         if(!node || SUGAR.util.isTouchScreen()) return;  
272                                         if(node.link == 'undefined' || node.link == '') return;
273                                         window.location.href=node.link;
274                                         }
275                                   },
276                                   //labels offset position
277                                   labelOffset: 5,
278                                   //bars style
279                                   type: useGradients? chartConfig["lineType"]+':gradient' : chartConfig["lineType"],
280                                   //whether to show the aggregation of the values
281                                   showAggregates:true,
282                                   //whether to show the labels for the bars
283                                   showLabels:true,
284                                   //labels style
285                                   Label: {
286                                         type: labelType, //Native or HTML
287                                         size: 12,
288                                         family: css["font-family"],
289                                         color: css["color"],
290                                         colorAlt: "#ffffff"
291                                   },
292                                   //add tooltips
293                                   Tips: {
294                                         enable: true,
295                                         onShow: function(tip, elem) {
296                                           if(elem.link != 'undefined' && elem.link != '') {
297                                                 drillDown = (SUGAR.util.isTouchScreen()) ? "<br><a href='"+ elem.link +"'>Click to drilldown</a>" : "<br>Click to drilldown";
298                                           } else {
299                                                 drillDown = "";
300                                           }
301
302                                           if(elem.valuelabel != 'undefined' && elem.valuelabel != undefined && elem.valuelabel != '') {
303                                                 var value = "elem.valuelabel";
304                                           } else {
305                                                 var value = "elem.value";
306                                           }
307                                           
308                                           if(elem.collision) {
309                                                 eval("var name = elem."+chartConfig["tip"]+";");
310                                                 var content = '<table>';
311                                                 
312                                                 for(var i=0; i<name.length; i++) {
313                                                         content += '<tr><td><b>' + name[i] + '</b>:</td><td> ' + elem.value[i] + ' - ' + elem.percentage[i] + '%' + '</td></tr>';
314                                                 }
315                                                 content += '</table>';
316                                                 tip.innerHTML = content;
317                                           } else {
318                                                 eval("tip.innerHTML = '<b>' + elem."+chartConfig["tip"]+" + '</b>: ' + "+value+" + ' - ' + elem.percentage + '%' + drillDown"); 
319                                           }
320                                         }
321                                   }
322                                 });
323                                 //load JSON data.
324                                 lineChart.loadJSON(json);
325                                 //end
326                                 
327                                 /*
328                                 var list = $jit.id('id-list'),
329                                         button = $jit.id('update'),
330                                         orn = $jit.id('switch-orientation');
331                                 //update json on click 'Update Data'
332                                 $jit.util.addEvent(button, 'click', function() {
333                                   var util = $jit.util;
334                                   if(util.hasClass(button, 'gray')) return;
335                                   util.removeClass(button, 'white');
336                                   util.addClass(button, 'gray');
337                                   barChart.updateJSON(json2);
338                                 });
339                                 */
340                                 //dynamically add legend to list
341                                 var list = $jit.id('legend'+chartId);
342                                 var legend = lineChart.getLegend(),
343                                         cols = (typeof SUGAR == 'undefined' || typeof SUGAR.mySugar == 'undefined') ? 8 : 4,
344                                         rows = Math.ceil(legend["name"].length/cols),
345                                         table = "<table cellpadding='0' cellspacing='0' align='left'>";
346                                 var j = 0;
347                                 for(i=0;i<rows;i++) {
348                                         table += "<tr>"; 
349                                         for(td=0;td<cols;td++) {
350                                                 
351                                                 table += '<td nowrap>';
352                                                 if(legend["name"][j] != undefined) {
353                                                         table += '<div class=\'query-color\' style=\'background-color:'
354                                                           + legend["color"][j] +'\'>&nbsp;</div>' + legend["name"][j];
355                                                 }
356                                                   
357                                                 table += '</td>';
358                                                 j++;
359                                                 }
360                                         table += "</tr>"; 
361                                 }
362                                 
363                                         table += "</table>";
364                                 list.innerHTML = table;
365                                 
366                                 
367                                 //save canvas to image for pdf consumption
368                                 $jit.util.saveImageTest(chartId,jsonFilename,chartConfig["imageExportType"]);
369                                 
370                                 
371                                         }
372                                 }
373                                                 
374                                 var callback =
375                                 {
376                                   success:handleSuccess,
377                                   failure:handleFailure,
378                                   argument: { foo:'foo', bar:''}
379                                 };
380                                 
381                                 var request = YAHOO.util.Connect.asyncRequest('GET', jsonFilename + "?r=" + new Date().getTime(), callback);
382                                 break;
383                         
384                                 
385                         case "pieChart":
386
387                                 var handleFailure = function(o){
388                                 alert('fail');
389                                         if(o.responseText !== undefined){
390                                                 alert('failed');
391                                         }
392                                 }       
393                                 var handleSuccess = function(o){
394
395                                         if(o.responseText !== undefined){                       
396                                         var json = eval('('+o.responseText+')');
397                                         var properties = $jit.util.splat(json.properties)[0];   
398
399                                                 //init BarChart
400                                 var pieChart = new $jit.PieChart({
401                                   //id of the visualization container
402                                   injectInto: chartId,
403                                   //whether to add animations
404                                   animate: false,
405                                   renderBackground: chartConfig['imageExportType'] == "jpg" ? true: false,
406                                   backgroundColor: 'rgb(255,255,255)',
407                                   colorStop1: 'rgba(255,255,255,.8)',
408                                   colorStop2: 'rgba(255,255,255,0)',    
409                                   labelType: properties['labels'],
410                                   hoveredColor: false,
411                                   //offsets
412                                   offset: 50,
413                                   sliceOffset: 0,
414                                   labelOffset: 30,
415                                   //slice style
416                                   type: useGradients? chartConfig["pieType"]+':gradient' : chartConfig["pieType"],
417                                   //whether to show the labels for the slices
418                                   showLabels:true,
419                                   Events: {
420                                         enable: true,
421                                         onClick: function(node) {  
422                                         if(!node || SUGAR.util.isTouchScreen()) return;  
423                                         if(node.link == 'undefined' || node.link == '') return;
424                                         window.location.href=node.link;
425                                         }
426                                   },
427                                   //label styling
428                                   Label: {
429                                         type: labelType, //Native or HTML
430                                         size: 12,
431                                         family: css["font-family"],
432                                         color: css["color"]
433                                   },
434                                   //enable tips
435                                   Tips: {
436                                         enable: true,
437                                         onShow: function(tip, elem) {
438                                           if(elem.link != 'undefined' && elem.link != '') {
439                                                 drillDown = (SUGAR.util.isTouchScreen()) ? "<br><a href='"+ elem.link +"'>Click to drilldown</a>" : "<br>Click to drilldown";
440                                           } else {
441                                                 drillDown = "";
442                                           }
443                                           
444                                           if(elem.valuelabel != 'undefined' && elem.valuelabel != undefined && elem.valuelabel != '') {
445                                                 value = "elem.valuelabel";
446                                           } else {
447                                                 value = "elem.value";
448                                           }
449                                            eval("tip.innerHTML = '<b>' + elem.label + '</b>: ' + "+ value +" + ' - ' + elem.percentage + '%' + drillDown");
450                                         }
451                                   }
452                                 });
453                                 //load JSON data.
454                                 pieChart.loadJSON(json);
455                                 //end
456                                 //dynamically add legend to list
457                                 var list = $jit.id('legend'+chartId);
458                                 var legend = pieChart.getLegend(),
459                                         cols = (typeof SUGAR == 'undefined' || typeof SUGAR.mySugar == 'undefined') ? 8 : 4,
460                                         rows = Math.ceil(legend["name"].length/cols);
461                                         table = "<table cellpadding='0' cellspacing='0' align='left'>";
462                                 var j = 0;
463                                 for(i=0;i<rows;i++) {
464                                         table += "<tr>"; 
465                                         for(td=0;td<cols;td++) {
466                                                 
467                                                 table += '<td nowrap>';
468                                                 if(legend["name"][j] != undefined) {
469                                                         table += '<div class=\'query-color\' style=\'background-color:'
470                                                           + legend["color"][j] +'\'>&nbsp;</div>' + legend["name"][j];
471                                                 }
472                                                   
473                                                 table += '</td>';
474                                                 j++;
475                                                 }
476                                         table += "</tr>"; 
477                                 }
478                                 
479                                         table += "</table>";
480                                 list.innerHTML = table;
481                                 
482                                                                 
483                                 //save canvas to image for pdf consumption
484                                 $jit.util.saveImageTest(chartId,jsonFilename,chartConfig["imageExportType"]);
485                                 }
486                         }
487                                                                 
488                                 var callback =
489                                 {
490                                   success:handleSuccess,
491                                   failure:handleFailure,
492                                   argument: { foo:'foo', bar:''}
493                                 };
494                                 
495                                 var request = YAHOO.util.Connect.asyncRequest('GET', jsonFilename + "?r=" + new Date().getTime(), callback);
496                                                         
497                                 break;
498                                 
499                                 
500                         case "funnelChart":
501
502                                 var handleFailure = function(o){
503                                 alert('fail');
504                                         if(o.responseText !== undefined){
505                                                 alert('failed');
506                                         }
507                                 }       
508                                 var handleSuccess = function(o){
509
510                                         if(o.responseText !== undefined && o.responseText != "No Data"){        
511                                         var json = eval('('+o.responseText+')');
512
513                                 var properties = $jit.util.splat(json.properties)[0];   
514
515                                 //init Funnel Chart
516                                 var funnelChart = new $jit.FunnelChart({
517                                   //id of the visualization container
518                                   injectInto: chartId,
519                                   //whether to add animations
520                                   animate: false,
521                                   renderBackground: chartConfig['imageExportType'] == "jpg" ? true: false,
522                                   backgroundColor: 'rgb(255,255,255)',
523                                   colorStop1: 'rgba(255,255,255,.8)',
524                                   colorStop2: 'rgba(255,255,255,0)',    
525                                   //orientation setting should not be changed
526                                   orientation: "vertical",
527                                   hoveredColor: false,
528                                   Title: {
529                                         text: properties['title'],
530                                         size: 16,
531                                         color: '#444444',
532                                         offset: 20
533                                   },
534                                   Subtitle: {
535                                         text: properties['subtitle'],
536                                         size: 11,
537                                         color: css["color"],
538                                         offset: 20
539                                   },
540                                   //segment separation
541                                   segmentOffset: 20,
542                                   //visualization offset
543                                   Margin: {
544                                         top:20,
545                                         left: 20,
546                                         right: 20,
547                                         bottom: 20
548                                   },
549                                   Events: {
550                                         enable: true,
551                                         onClick: function(node) {  
552                                         if(!node || SUGAR.util.isTouchScreen()) return;  
553                                         if(node.link == 'undefined' || node.link == '') return;
554                                         window.location.href=node.link;
555                                         }
556                                   },
557                                   //labels offset position
558                                   labelOffset: 10,
559                                   //bars style
560                                   type: useGradients? chartConfig["funnelType"]+':gradient' : chartConfig["funnelType"],
561                                   //whether to show the aggregation of the values
562                                   showAggregates:true,
563                                   //whether to show the labels for the bars
564                                   showLabels:true,
565                                   //labels style
566                                   Label: {
567                                         type: labelType, //Native or HTML
568                                         size: 12,
569                                         family: css["font-family"],
570                                         color: css["color"],
571                                         colorAlt: "#ffffff"
572                                   },
573                                   //add tooltips
574                                   Tips: {
575                                         enable: true,
576                                         onShow: function(tip, elem) {
577                                           if(elem.link != 'undefined' && elem.link != '') {
578                                                 drillDown = (SUGAR.util.isTouchScreen()) ? "<br><a href='"+ elem.link +"'>Click to drilldown</a>" : "<br>Click to drilldown";
579                                           } else {
580                                                 drillDown = "";
581                                           }
582
583                                           if(elem.valuelabel != 'undefined' && elem.valuelabel != undefined && elem.valuelabel != '') {
584                                                 value = "elem.valuelabel";
585                                           } else {
586                                                 value = "elem.value";
587                                           }
588                                           eval("tip.innerHTML = '<b>' + elem."+chartConfig["tip"]+" + '</b>: ' + "+value+"  + ' - ' + elem.percentage + '%' +  drillDown");
589                                         }
590                                   }
591                                 });
592                                 //load JSON data.
593                                 funnelChart.loadJSON(json);
594                                 //end
595                                 
596                                 /*
597                                 var list = $jit.id('id-list'),
598                                         button = $jit.id('update'),
599                                         orn = $jit.id('switch-orientation');
600                                 //update json on click 'Update Data'
601                                 $jit.util.addEvent(button, 'click', function() {
602                                   var util = $jit.util;
603                                   if(util.hasClass(button, 'gray')) return;
604                                   util.removeClass(button, 'white');
605                                   util.addClass(button, 'gray');
606                                   barChart.updateJSON(json2);
607                                 });
608                                 */
609                                 //dynamically add legend to list
610                                 var list = $jit.id('legend'+chartId);
611                                 var legend = funnelChart.getLegend(),
612                                         cols = (typeof SUGAR == 'undefined' || typeof SUGAR.mySugar == 'undefined') ? 8 : 4,
613                                         rows = Math.ceil(legend["name"].length/cols);
614                                         table = "<table cellpadding='0' cellspacing='0' align='left'>";
615                                 var j = 0;
616                                 for(i=0;i<rows;i++) {
617                                         table += "<tr>"; 
618                                         for(td=0;td<cols;td++) {
619                                                 
620                                                 table += '<td nowrap>';
621                                                 if(legend["name"][j] != undefined) {
622                                                         table += '<div class=\'query-color\' style=\'background-color:'
623                                                           + legend["color"][j] +'\'>&nbsp;</div>' + legend["name"][j];
624                                                 }
625                                                   
626                                                 table += '</td>';
627                                                 j++;
628                                                 }
629                                         table += "</tr>"; 
630                                 }
631                                 
632                                         table += "</table>";
633                                 list.innerHTML = table;
634                                                                 
635                                 //save canvas to image for pdf consumption
636                                 $jit.util.saveImageTest(chartId,jsonFilename,chartConfig["imageExportType"]);
637                                 }
638                         }
639                                                 
640                                 var callback =
641                                 {
642                                   success:handleSuccess,
643                                   failure:handleFailure,
644                                   argument: { foo:'foo', bar:''}
645                                 };
646                                 
647                                 var request = YAHOO.util.Connect.asyncRequest('GET', jsonFilename + "?r=" + new Date().getTime(), callback);
648                                 break;
649                                 
650                                 
651                                 
652                         case "gaugeChart":
653
654                                 var handleFailure = function(o){
655                                 alert('fail');
656                                         if(o.responseText !== undefined){
657                                                 alert('failed');
658                                         }
659                                 }       
660                                 var handleSuccess = function(o){
661
662                                         if(o.responseText !== undefined){                       
663                                         var json = eval('('+o.responseText+')');
664                                         var properties = $jit.util.splat(json.properties)[0];   
665
666                                                 //init Gauge Chart
667                                 var gaugeChart = new $jit.GaugeChart({
668                                   //id of the visualization container
669                                   injectInto: chartId,
670                                   //whether to add animations
671                                   animate: false,
672                                   renderBackground: chartConfig['imageExportType'] == "jpg" ? true: false,
673                                   backgroundColor: 'rgb(255,255,255)',
674                                   colorStop1: 'rgba(255,255,255,.8)',
675                                   colorStop2: 'rgba(255,255,255,0)',
676                                   labelType: properties['labels'],
677                                   hoveredColor: false,
678                                   Title: {
679                                         text: properties['title'],
680                                         size: 16,
681                                         color: '#444444',
682                                         offset: 20
683                                   },
684                                   Subtitle: {
685                                         text: properties['subtitle'],
686                                         size: 11,
687                                         color: css["color"],
688                                         offset: 5
689                                   },
690                                   //offsets
691                                   offset: 20,
692                                   gaugeStyle: {
693                                         backgroundColor: '#aaaaaa',
694                                         borderColor: '#999999',
695                                         needleColor: 'rgba(255,0,0,.8)',
696                                         borderSize: 4,
697                                         positionFontSize: 24,
698                                         positionOffset: 2
699                                   },
700                                   //slice style
701                                   type: useGradients? chartConfig["gaugeType"]+':gradient' : chartConfig["gaugeType"],
702                                   //whether to show the labels for the slices
703                                   showLabels:true,
704                                   Events: {
705                                         enable: true,
706                                         onClick: function(node) {  
707                                         if(!node || SUGAR.util.isTouchScreen()) return;  
708                                         if(node.link == 'undefined' || node.link == '') return;
709                                         window.location.href=node.link;
710                                         }
711                                   },
712                                   //label styling
713                                   Label: {
714                                         type: labelType, //Native or HTML
715                                         size: 12,
716                                         family: css["font-family"],
717                                         color: css["color"]
718                                   },
719                                   //enable tips
720                                   Tips: {
721                                         enable: true,
722                                         onShow: function(tip, elem) {
723                                           if(elem.link != 'undefined' && elem.link != '') {
724                                                 drillDown = (SUGAR.util.isTouchScreen()) ? "<br><a href='"+ elem.link +"'>Click to drilldown</a>" : "<br>Click to drilldown";
725                                           } else {
726                                                 drillDown = "";
727                                           }
728                                           if(elem.valuelabel != 'undefined' && elem.valuelabel != undefined && elem.valuelabel != '') {
729                                                 value = "elem.valuelabel";
730                                           } else {
731                                                 value = "elem.value";
732                                           }
733                                            eval("tip.innerHTML = '<b>' + elem.label + '</b>: ' + "+ value +" + drillDown");
734                                         }
735                                   }
736                                 });
737                                 //load JSON data.
738                                 gaugeChart.loadJSON(json);
739
740                                 
741                                 var list = $jit.id('legend'+chartId);
742                                 var legend = gaugeChart.getLegend(),
743                                         cols = (typeof SUGAR == 'undefined' || typeof SUGAR.mySugar == 'undefined') ? 8 : 4,
744                                         rows = Math.ceil(legend["name"].length/cols);
745                                         table = "<table cellpadding='0' cellspacing='0' align='left'>";
746                                 var j = 1;
747                                 for(i=0;i<rows;i++) {
748                                         table += "<tr>"; 
749                                         for(td=0;td<cols;td++) {
750                                                 
751                                                 table += '<td nowrap>';
752                                                 if(legend["name"][j] != undefined) {
753                                                         table += '<div class=\'query-color\' style=\'background-color:'
754                                                           + legend["color"][j] +'\'>&nbsp;</div>' + legend["name"][j];
755                                                 }
756                                                   
757                                                 table += '</td>';
758                                                 j++;
759                                                 }
760                                         table += "</tr>"; 
761                                 }
762                                 
763                                         table += "</table>";
764                                 list.innerHTML = table;
765                                 
766                                                                 
767                                 //save canvas to image for pdf consumption
768                                 $jit.util.saveImageTest(chartId,jsonFilename,chartConfig["imageExportType"]);
769                                 }
770                         }
771                                                                 
772                                 var callback =
773                                 {
774                                   success:handleSuccess,
775                                   failure:handleFailure,
776                                   argument: { foo:'foo', bar:''}
777                                 };
778                                 
779                                 var request = YAHOO.util.Connect.asyncRequest('GET', jsonFilename + "?r=" + new Date().getTime(), callback);
780                                                         
781                                 break;
782                                 
783                         }
784                 }