【问题标题】:Dynamic CategoryAxis for MVC Kendo ChartMVC Kendo Chart 的动态 CategoryAxis
【发布时间】:2017-05-25 17:25:52
【问题描述】:

目前我有这个并且效果很好。我需要的是 CategoryAxis 中的类别是动态的,而不是静态的 .Categories("1", "2", "3", "4", "5 ")..

我已经有了我想从我的模型中输入的值,它的 @item.SurveyLinearCounts.FirstOrDefault().Min 是最小值,@item.SurveyLinearCounts.FirstOrDefault().Max 是最大值

我该怎么做?

@(Html.Kendo().Chart<AnalyzeResponseViewModel>()
                                  .Name(@item.SurveyQuestionID.ToString())
                                  .Legend(legend => legend
                                      .Position(ChartLegendPosition.Top)
                                      .Visible(true)
                                  )
                                  .ChartArea(chartArea => chartArea
                                      .Background("transparent")
                                  )
                                  .Series(series =>
                                  {
                                      series.Column(model => model.ResponseCount).Name("Count").Tooltip(tooltip => tooltip.Visible(true).Template("#= series.name #: #=  value #"));
                                  })
                                   .CategoryAxis(axis => axis
                                      .Categories("1", "2", "3", "4", "5")
                                      .MajorGridLines(lines => lines.Visible(false))
                                  )
                              .
                              )
                                  .ValueAxis(axis => axis
                                      .Numeric()
                                      .Line(line => line.Visible(false))
                                      .MajorGridLines(lines => lines.Visible(true))
                                  )
                                  .DataSource(ds => ds
                                      .Read(read => read.Action("GetSurveyResponseChart", "DataSource", new { item.SurveyQuestionID })))
                                  .Tooltip(tooltip => tooltip.Visible(true).Template("#= series.name #: #= value #")))

【问题讨论】:

  • 不清楚你想要什么。您是否只想在图表生成后更新类别标签?
  • 我想用我的模型中的值动态设置标签

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


【解决方案1】:

假设您想要的值在 item.SurveyLinearCounts 属性中,您应该能够执行以下操作:

.CategoryAxis(axis => axis
    .Categories(item.SurveyLinearCounts)
    .MajorGridLines(lines => lines.Visible(false))
)

如果那里有您想要的其他属性,您可以执行以下操作:

.Categories(item.SurveyLinearCounts.Select(x => x.MyProp))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-01
    • 1970-01-01
    • 2013-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多