データベースからデータを取得し、そのデータをグラファエル チャート内に表示する方法を理解したいと思います。
私は ASP.NET MVC3 で作業していますが、それを機能させる方法が本当にわかりません。
どんな助けでも本当に感謝しています。
1 に答える
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);
}
ここでは、円グラフも作成する ajax 側です。
jQuery.getJSON("/コントローラー名/アクション名", 関数 (データ) {
// # 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 });
}
});
});
于 2012-05-08T19:59:47.610 に答える