Roo/bootstrap/Graph.js
authorEdward <edward@roojs.com>
Mon, 1 Dec 2014 03:02:16 +0000 (11:02 +0800)
committerEdward <edward@roojs.com>
Mon, 1 Dec 2014 03:02:16 +0000 (11:02 +0800)
Roo/bootstrap/Graph.js

index a2c213c..8c5042c 100644 (file)
@@ -19,6 +19,8 @@
  @cfg {number} g_r radius (pie)
  @cfg {number} g_height height of the chart (respected by all elements in the set)
  @cfg {number} g_width width of the chart (respected by all elements in the set)
+ @cfg {Object} g_title The title of the chart
+    
  -{Array}  values
  -opts (object) options for the chart 
      o {
@@ -72,6 +74,12 @@ Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component,  {
         g_gutter: '20%'
 
     },
+    title : {
+        text : '',
+        x : 150,
+        y : 50,
+        attr : { font: "20px 'Fontin Sans', Fontin-Sans, sans-serif" }
+    },
 
     getAutoCreate : function(){
         
@@ -112,12 +120,12 @@ Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component,  {
                 //     //yvalues : cols,
                    
                 // });
-        var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
-        
-        this.load(null,xdata,{
-                axis : "0 0 1 1",
-                axisxlabels :  xdata
-                });
+//        var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
+//        
+//        this.load(null,xdata,{
+//                axis : "0 0 1 1",
+//                axisxlabels :  xdata
+//                });
 
     },
 
@@ -129,33 +137,40 @@ Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component,  {
         if(!opts){
             opts = this.opts;
         }
-        var chart_title = '',
-                    r = this.raphael,
-                    fin = function () {
-                        this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
-                    },
-                    fout = function () {
-                        this.flag.animate({opacity: 0}, 300, function () {this.remove();});
-                    };
+        var r = this.raphael,
+            fin = function () {
+                this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
+            },
+            fout = function () {
+                this.flag.animate({opacity: 0}, 300, function () {this.remove();});
+            };
 
         switch(graphtype){
             case 'bar':
                 this.raphael.barchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
-                chart_title = 'This is Vertical Barchart';
+                this.title.text = this.title.text || 'This is Vertical Barchart';
                 break;
             case 'hbar':
                 this.raphael.hbarchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
-                chart_title = 'This is Horizontal Barchart';
+                this.title.text = this.title.text || 'This is Horizontal Barchart';
                 break;
             case 'pie':
                 opts = { legend: ["%% - Enterprise Users", "% - ddd","Chrome Users"], legendpos: "west", 
                 href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]};
-                    this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts);
-                chart_title = 'This is Piechart';
+            
+                this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts);
+                
+                this.title.text = this.title.text || 'This is Piechart';
                 break;
 
         }
-        this.raphael.text(150,50,chart_title).attr({ font: "20px 'Fontin Sans', Fontin-Sans, sans-serif" });
+        
+        this.raphael.text(this.title.x, this.title.y, this.title.text).attr(this.title.attr);
+    },
+    
+    setTitle: function(o)
+    {
+        this.title = o;
     },
     
     initEvents: function() {