Графические диаграммы с динамическими данными из базы данных с использованием ASP.NET MVC3

Я хотел бы понять, как получить данные из базы данных и показать эти данные в диаграмме Graphael.
Я работаю в ASP.NET MVC3, и я действительно не понимаю, как заставить вещи работать.
Любая помощь очень ценится.

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 ("/ ControllerName / ActionName", функция (данные) {

// # 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 });
    }
});

});

Другие вопросы по тегам