Lazy Highcharts drilldown mvc asp.net

时间:2015-07-07 14:59:48

标签: javascript asp.net-mvc highcharts

我需要在点击时加载下钻图表的数据而不是页面加载。

//Drill down for yearly periods
    @foreach(var item in Model)
        {
            <text>
         @item.QuestionType = {
            chart: {
                type: 'pie'
            },
            title: {
                text: '@item.Category.CategoryName'
            },
            subtitle: {
                text: '@item.QuestionType Over the last year'
            },
            series: [{
                name: '@item.QuestionType over the last year',
                data: [{
                    name: 'Yes',
                    y:@Html.Action("GetYear", new { id = @item.QuestionID, category = "Yes" }),
                    drilldown: '@item.QuestionType-Month',
                }, {
                    name: 'No',
                    y: @Html.Action("GetYear", new { id = @item.QuestionID, category = "No" }),
                    drilldown: '@item.QuestionType-Month',
                }]
            }]

        };
        </text>
        }



     //Drill down for entire periods per category

     @foreach(var cat in categories)
    {
        <text>
     @cat.CategoryName = {
         chart: {
             type: 'column'
         },
         title: {
             text: '@cat.CategoryName'
         },
         xAxis: {
             type: 'category',
             title: {
                 text: 'Categories in @cat.CategoryName'
             }
         },
         yAxis: {
             allowDecimals: false,
             title: {
                 text: 'Questions answered'
             }
         },
         plotOptions: {
             column: {
                 stacking: 'normal'
             }
         },
         series: [

             {
                 name: 'Yes',
                 data: [
                     @foreach(var item in Model)
                {
                        if(@item.CategoryID == @cat.CategoryID)
                        {
                            <text>
                         {
                             name: '@item.QuestionType',
                             y: @Html.Action("GetQuestion", new { id = @item.QuestionID, category = "Yes" }),
                             drilldown: @item.QuestionType,

                         },
                     </text>
                        }

                    }
                 ],
             }, {
                 name: 'No',
                 data: [
               @foreach(var item in Model)
                {
                  if(@item.CategoryID == @cat.CategoryID)
            {
                            <text>
                         {
                             name: '@item.QuestionType',
                             y: @Html.Action("GetQuestion", new { id = @item.QuestionID, category = "No" }),
                             drilldown: @item.QuestionType,

                         },
                        </text>
            }
        }
                 ]
             }]
     };
    </text>
        }



    //loop for first level
    $("#container").highcharts({
        chart: {
            type: 'column'
        },
        title: {

            text: 'All categories'
        },
        xAxis: {
            type: 'category'
        },
        yAxis: {
            title: {
                text: 'Questions answered'
            },

            allowDecimals: false,},

        legend: {
            enabled: false
        },

        plotOptions: {
            column: {
                stacking: 'normal'
            },
            series: {
                borderWidth: 0,
                dataLabels: {
                    enabled: true
                }
            }
        },

        series: [{
            name: "All categories",
            colorByPoint: true,
            data: [ @foreach(var item in categories)
                {
                <text>{
                name: '@item.CategoryName',
                y: @Html.Action("GetCategory", new {id = item.CategoryID}),
                drilldown: @item.CategoryName,
            },
            </text>
                }
            ]
        }]

    });

当前代码全部在页面加载时运行,使加载时间超过14秒, 我希望能够在点击图表上的某个点时加载正确的方法。

我见过像this这样的例子但是当我尝试实现它时,它没有显示出来。我想我可能会挣扎,因为我有堆叠列,这个代码用于普通列,我还需要在向下钻取时更改图表的布局,例如标题类别ect,这段代码不会这样做。

0 个答案:

没有答案