【问题标题】:Kendo chart grouped series sort issue剑道图表分组系列排序问题
【发布时间】:2021-07-09 12:45:15
【问题描述】:

我正在使用剑道图表在 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)
)

)

【问题讨论】:

    标签: jquery asp.net-mvc kendo-ui kendo-asp.net-mvc kendo-chart


    【解决方案1】:

    在 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 #");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多