2012-05-06 39 views

回答

1

很好我解決了這個問題! 我認爲這可能是有用的人太多其他:

這裏是控制器代碼:

public ActionResult ActionName() 
     { 
      List<String> data = new List<String>(); 
      data.Add("legend0_4"); 
      data.Add("legend1_5"); 
      data.Add("legend2_8"); 
      data.Add("legend3_12"); 
      data.Add("legend4_8"); 

      return Json(data, JsonRequestBehavior.AllowGet); 
     } 

這是阿賈克斯也創建餅圖:

jQuery.getJSON (「/ ControllerName/ActionName」,function(data){

// # Init 
var levels = [], values = []; 


for (var id in data) { 
    var compo = data[id].split("_"); 
    levels.push("%%.%% " + compo[0]); 
    values.push(parseInt(compo[1])); 
} 

var r = Raphael("accountCharts"), 
      pie = r.piechart(320, 240, 100, values, { legend: levels, legendpos: "west", href: ["http://raphaeljs.com", "http://g.raphaeljs.com"] }); 

r.text(320, 100, "Interactive Pie Chart").attr({ font: "20px sans-serif" }); 
pie.hover(function() { 
    this.sector.stop(); 
    this.sector.scale(1.1, 1.1, this.cx, this.cy); 

    if (this.label) { 
     this.label[0].stop(); 
     this.label[0].attr({ r: 7.5 }); 
     this.label[1].attr({ "font-weight": 800 }); 
    } 
}, function() { 
    this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce"); 

    if (this.label) { 
     this.label[0].animate({ r: 5 }, 500, "bounce"); 
     this.label[1].attr({ "font-weight": 400 }); 
    } 
}); 

});

相關問題