我们遇到的问题是,在我们开发的一个Kendo图表中,我们正在开发一些每周数据。我们发送给视图的JSON如下所示:
[
{"WeekofYear":45,"Value":96.08,"WeekBeginDate":"\/Date(1415422800000)\/"},
{"WeekofYear":46,"Value":97.40,"WeekBeginDate":"\/Date(1416027600000)\/"},
{"WeekofYear":47,"Value":96.50,"WeekBeginDate":"\/Date(1416632400000)\/"},
{"WeekofYear":48,"Value":93.93,"WeekBeginDate":"\/Date(1417237200000)\/"},
{"WeekofYear":49,"Value":96.76,"WeekBeginDate":"\/Date(1417842000000)\/"},
{"WeekofYear":50,"Value":94.50,"WeekBeginDate":"\/Date(1418446800000)\/"}
]
JSON中的日期表示相关周的每个星期六的日期。但是,当我们渲染图表时,它会显示星期日的日期,而不是屏幕截图中显示的日期。
我们在Razor引擎中使用以下代码生成图表:
@(Html.Kendo().Chart<Dashboard.Models.CentralScheduling>()
.Name("CallsAnswered")
.Title("% of Calls Answered")
.Legend(legend => legend.Visible(false))
.DataSource(dataSource => dataSource
.Read(read => read.Action("CentralScheduling", "Dashboard").Data("filterStatusData")))
.Series(series =>
{
series.Line(d => d.Value)
.Tooltip(t => t.Visible(true).Template("#=value#%"));
})
.CategoryAxis(axis => axis
.Categories(model => model.WeekBeginDate) //WeekBeginDate holds the date at the end of the week for this particular chart
.Labels(labels => labels.Format("MM/dd/yyyy")
.Rotation(-60)
)
)
.ValueAxis(axis => axis
.Numeric().Labels(labels => labels.Format("{0}%"))
.Max(100)
)
.SeriesColors("#3aafff","#ffb800","#a7008f","#99c900","#FF0000", "#002060")
)
filterStatusData函数设置我们在控制器中使用的标志,以便为调用图表生成JSON。
我无法解释为什么为图表选择不同的日期而不是我们提供的日期。
答案 0 :(得分:0)
一个选项 - 这是来自Telerik的 - 是将日期作为字符串从服务器而不是.Net DateTime对象传递。客户端将像处理日期对象一样解析它。使用此格式“yyyy-mm-dd HH:MM”
所以你的json会是这样的:
[
{"WeekofYear":45,"Value":96.08,"WeekBeginDate":"2014-12-16 07:00"},
...