【问题标题】:Kendo pie chart displays only empty area剑道饼图只显示空白区域
【发布时间】:2015-06-02 08:08:46
【问题描述】:

尽管在互联网上进行了所有搜索。我找不到我的代码有什么问题。 我只是想用我的数据库中的数据填充我的馅饼。这是我的代码:

数据访问功能: (这是我获取所有数据以填充我的馅饼)

   public static IEnumerable<PieModel> getTypesForStatistics()
    {
        var dbo = new UsersContext();
        var all = (from a in dbo.Note
                      select a).ToList();
        var results = all.GroupBy(item => item.language.lang)
                         .Select(g => new PieModel
                         {
                             Language = g.Key,
                             Count = g.Count()
                         });
        return results.ToList();

    }

还有我创建的模型:

   public class PieModel
    {
        public string Language { get; set; }
        public int Count { get; set; }
        // example : English,4 | Spanish,16 | German, 2 etc
    }

在我的控制器中:

  public class StatisticsController : Controller
    {
        //
        // GET: /Statistics/

        public ActionResult Index()
        {
            return View();      
        }

        [HttpPost]
        public ActionResult displayChart()
        {
            var results = Json(DAL.StatisticsAccess.getTypesForStatistics()); 
            return Json(results);
        }

    }

最后是我的观点:

@(Html.Kendo().Chart<DevelopmentNotesProject.Models.PieModel>()
        .Name("chart")
                .Title(title => title
                    .Text("")
                    .Position(ChartTitlePosition.Bottom))
        .Legend(legend => legend
            .Visible(false)
        )
                   .DataSource(ds => ds.Read(read => read.Action("displayChart", "Statistics")))
            .Series(series =>
            {
                series.Pie( model => model.Count,model => model.Language);
            })
        .Tooltip(tooltip => tooltip
            .Visible(true)
            .Format("{0}%")
        )


    )

提前感谢您花时间阅读我的代码。

【问题讨论】:

    标签: c# asp.net-mvc-4 telerik kendo-asp.net-mvc pie-chart


    【解决方案1】:

    我找到了一个以不同方式做事的好解决方案:

    控制器:

    public ActionResult Index()
    {
        IEnumerable <PieModel> pieModel = DAL.StatisticsAccess.getTypesForStatistics();
        return View(pieModel);      
    }
    
    [HttpPost]
    public ActionResult displayChart() // no longer used
    {
        var results = Json(DAL.StatisticsAccess.getTypesForStatistics()); 
        return Json(results);
    }
    

    查看:

    @model IEnumerable<DevelopmentNotesProject.Models.PieModel>
    ..
    ...
    ....
        @(Html.Kendo().Chart(Model)
            .Name("chart")
                    .Title(title => title
                        .Text("")
                        .Position(ChartTitlePosition.Bottom))
            .Legend(legend => legend
                .Visible(false)
            )
                       //.DataSource(ds => ds.Read(read => read.Action("displayChart", "Statistics")))
                .Series(series =>
                {
                    series.Pie( model => model.Count,model => model.Language);
                })
    
    
    
    
            .Tooltip(tooltip => tooltip
                .Visible(true)
                .Format("{0}%")
            )
    
    
        )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-29
      • 2021-02-15
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多