剑道图分组系列排序问题

问题描述

我正在使用 Kendo 图表在 ASP.net MVC 项目中显示分组系列。 Chart 默认根据 UserName 字段对系列进行排序。我需要在 Legends 中显示 UserName 字段,但需要使用 UserID 字段对系列进行排序。这可以通过禁用使用 UserName 应用的默认排序来实现,或者可以将排序字段更改为 UserID。数据源排序在这里不起作用。我怎样才能做到这一点? 我的代码如下:

@(Html.Kendo().Chart<TestProject.Models.ItemViewModel>
()
.Name("TestChart")
.Legend(legend => legend.Position(ChartLegendPosition.Right)
    .Orientation(ChartLegendOrientation.Vertical)
)
.Tooltip(tooltip => tooltip.Visible(true))
.DataSource(ds => ds
    .Read(read => read.Action("Test_Chart_Read","Test"))
    .Group(group => group.Add(model => model.UserName))
    .Sort(sort => sort.Add(m=>m.UserID).Ascending())
)
.Series(series =>{series.Bar(model => model.Salary).Name("#= group.value #");})
.CategoryAxis(axis => axis
    .Categories(model => model.UserName)
    .Labels(l => l.Rotation(-45).Position(ChartAxisLabelsPosition.Start).Visible(false))
)
.ValueAxis(axis => axis
.Numeric()
.Line(line => line.Visible(true))
)
.Tooltip(tooltip => tooltip
.Visible(true)
)

)

Chart with default sorting

解决方法

在 Telerik 论坛 (https://www.telerik.com/forums/legend-sort-order-issue) 上的一篇旧帖子中找到了解决方案。

尽管它给出了“GroupNameTempalte”已过时的警告,但该解决方案运行良好。以下是代码更改:

.DataSource(dataSource => dataSource
        .Read(read => read.Action("_StockData","Scatter_Charts"))
        .Group(group => group.Add(model => model.MonthNumber))
    )
    .Series(series => {
        series.Line(model => model.Close)
            .Name("close")
            .GroupNameTemplate("#= group.items[0].MonthName #");

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...