0

努力将模型中的数据显示到剑道条形图中。我想要条形图显示结果如下图所示

在此处输入图像描述

控制器返回有效数据,但图表无法正确显示数据。

型号是

public class FeeCollectionViewModel
 {
     [Key]
     public int FeeCollectionID { get; set; }
     public int StudentID { get; set; }
     public int FeeModeID { get; set; }
     public int FeeTypeID { get; set; }
     public string FeeTypeName { get; set; }
     public double Amount { get; set; }
     public DateTime CollectionDate { get; set; }
  }

这是视图

@using Kendo.Mvc.UI
@using Kendo.Mvc.Extensions
@{
    ViewBag.Title = "Fee Statistics";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Fee Statistics</h2>

 @(Html.Kendo().Chart<SMS.ViewModels.FeeCollectionViewModel>()
        .Name("chart")
        .Title("Today's Collection")
        .Legend(legend => legend
        .Position(ChartLegendPosition.Top)
        )
        .DataSource(ds => ds
            .Read(read => read.Action("TodaysCollection_Read", "FeeCollections"))
            .Group(group => group.Add(model => model.FeeTypeName))
        )
        .Series(series =>
        {
            series.Column(model => model.Amount).Name("Amount Collected");
        })
        .CategoryAxis(axis => axis
            .Categories(model => model.FeeTypeName)
            .Labels(labels => labels.Rotation(-90))
            .MajorGridLines(lines => lines.Visible(false))
        )
        .ValueAxis(axis => axis.Numeric()
            .Labels(labels => labels.Format("{0:N0}"))
            .MajorUnit(10000)
            .Line(line => line.Visible(false))
        )
        .Tooltip(tooltip => tooltip
            .Visible(true)
            .Format("{0:N0}")
        )
)
4

2 回答 2

0

我认为您不解析数据以输入图表 我通过输入图表创建对象并传递数据

我的图表

于 2020-06-17T02:16:18.083 回答
0

Kendo Chart 不执行 groupby sum。我必须在控制器中执行此操作并将生成的模型传递给图表。

    List<FeeCollectionChartViewModel> result = (from f in feeCollections
                                                group f by f.FeeTypeName into g
                                                select new FeeCollectionChartViewModel()
                                                        {
                                                            FeeTypeName = g.Key,
                                                            Amount = g.Sum(x => x.Amount)
                                                        }).ToList();
     return Json(result)
于 2017-05-09T11:42:18.617 回答