1

こんにちは、私はこのような出力データを取得するstoredprocedureを持っています

var ログに記録されたバグ

    projectName ProjectYear ProjectMonth    Week1   Week2   Week3   Week4 Week5
    Ecommerce       2012           8          0      1       4       3    0

var ログに記録されたバグ

    projectName ProjectYear ProjectMonth    Week1   Week2   Week3   Week4 Week5 
    Ecommerce       2012           8          2      2       8       3    0

MVCアプリケーションでこのstoredprocedureを呼び出し、このデータをJsonとしてこのように返します

    public ActionResult Index()
    {
        return View();
    }
    public JsonResult CreatedBugs()
    {
        int year;
        int month;
        int projectid;
        year = 2012;
        month = 8;
        projectid = 16;       
        var loggedbugs = db.ExecuteStoreQuery<LoggedBugs>("LoggedBugs @Year,@Month,@ProjectID", new SqlParameter("@Year", year), new SqlParameter("@Month", month), new SqlParameter("@ProjectID", projectid)).ToList();
       var ClosedBugs = db.ExecuteStoreQuery<LoggedBugs>("ClosedBugs @Year,@Month,@ProjectID", new SqlParameter("@Year", year), new SqlParameter("@Month", month), new SqlParameter("@ProjectID", projectid)).ToList();
        var model = new LoggedBugs
        {
            LoggedBugsCount = loggedbugs,
           ClosedBugs = ClosedBugs
        };
        return Json(model, JsonRequestBehavior.AllowGet);
    }  

モデルはここでレコード数 2 を返します...だから今私がやりたいことは...このデータを折れ線グラフにバインドする必要があります.LoggedBugsCount には別の行があり、ClosedBugs には別の行が必要です...そして週がオンになっている必要がありますX軸とY軸にはカウントが必要です....

このデータ折れ線グラフをハイチャートにバインドする方法について、ここで誰か助けてもらえますか..これは私が今試していることですが、結果はありません

   <script type="text/javascript">
    $(document).ready(function () {
        alert(1);
        $.getJSON('<%= Url.Action("CreatedBugs","WeeklyLoggedBugs") %>', {}, function (data) {
            var json = data;
            alert(data);
            var loggedbugs = [];
            var closedbugs = [];
            for (var i in json) {
                // var serie = new Array(json[i].Projects, json[i].Bugs);
                //jsondata.push([json[i].projectName, json[i].ProjectYear, json[i].ProjectMonth, json[i].Week1, json[i].Week2, json[i].Week3, json[i].Week4, json[i].Week5]);
                loggedbugs.push([json[i].LoggedBugsCount]);
                closedbugs.push([json[i].ClosedBugs]);

            }
            chart.series[0].data = loggedbugs;
            chart.series[1].data = closedbugs;
            var chart;
            chart = new Highcharts.Chart({
                chart: {
                    renderTo: 'container',
                    type: 'line'
                },
                title: {
                    text: 'Daily Reports'
                },
                subtitle: {
                    text: 'Logged Bugs'
                },
                xAxis: {
                    categories: ['Week1', 'Week2', 'Week3', 'Week4', 'Week5']
                },
                yAxis: {
                    title: {
                        text: 'Temperature (°C)'
                    }
                },
                tooltip: {
                    enabled: false,
                    formatter: function () {
                        return '<b>' + this.series.name + '</b><br/>' +
                    this.x + ': ' + this.y + '°C';
                    }
                },
                plotOptions: {
                    line: {
                        dataLabels: {
                            enabled: true
                        },
                        enableMouseTracking: false
                    }
                },
                series: [{
                    type: 'line',
                    name: 'Logged Bugs'

                },
                    {
                        type: 'line',
                        name: 'ClosedBugs'

                    }]
            });
        });
    });       
</script>
4

1 に答える 1

2

こちらをご覧ください

chart.series[0].data = loggedbugs;
chart.series[1].data = closedbugs;
var chart;
chart = new Highcharts.Chart({
      ........
});

まず、チャートを作成し、チャート変数を定義する前に、シリーズにデータを追加しています。

次に、次を使用してデータを連続して設定できます。

series: [{
       name: 'Logged Bugs',
       data: loggedbugs

},
{
      name: 'ClosedBugs',
      data: closedbugs
}]

だから、あなたのイベントは必要ありません

chart.series[0].data = loggedbugs;
chart.series[1].data = closedbugs;

例を次に示します: http://jsfiddle.net/mhardik/JRq7Z/

編集:私はasp.net MVC3を知りません

データを取得しているかどうかを確認します。console.log()FF を使用している場合は、コンソールに応答を出力します。

for (var i in json) {
         loggedbugs.push([json[i].LoggedBugsCount]);
         closedbugs.push([json[i].ClosedBugs]);

 }
 // Check
 console.log(loggedbugs); console.log(closedbugs);
于 2012-08-30T05:28:50.810 に答える