我正在使用 flot 在 mvc3 网页中显示堆叠的时间序列。图表正确显示 xaxis 格式不影响图表。
我使用以下代码将数据传递给视图
var range = DateTime.Today.AddDays(-30);
var graphData = _db.UpdateStatistics.Where(x => x.Day > range).OrderBy(x=> x.Day);
var viewGraph = new SubscriptionUpdatesGraphViewModel();
foreach (var entry in graphData)
{
viewGraph.Total.Add(new Tuple<long, int>(entry.Day.Ticks, entry.Total));
viewGraph.Attention.Add(new Tuple<long, int>(entry.Day.Ticks, entry.Attention));
viewGraph.Complete.Add(new Tuple<long, int>(entry.Day.Ticks, entry.Complete));
viewGraph.Fail.Add(new Tuple<long, int>(entry.Day.Ticks, entry.Failed));
viewGraph.Notify.Add(new Tuple<long, int>(entry.Day.Ticks, entry.Pending));
}
ViewBag.Graph = viewGraph;
return View(result);
在视图中,我有以下内容
<script id="source" type="text/javascript">
$(function () {
var total = @ViewBag.Graph.SerialisedTotal;
var attention = @ViewBag.Graph.SerialisedAttention;
var notify = @ViewBag.Graph.SerialisedNotify;
var complete = @ViewBag.Graph.SerialisedComplete;
var fail = @ViewBag.Graph.SerialisedFail;
var stack = true, bars = false, lines = true, steps = false;
function plotWithOptions() {
$.plot($("#graph"), [{label:'Need Attention',data:attention},
{label:'Ready to apply',data:notify},
{label:'Failed',data:fail},
{label:'Completed',data:complete}],
{ series: {stack : stack,
lines: { show: lines,
fill: true,
steps: steps } ,
xaxis: {mode: 'time' ,
timeformat: "%d",
tickSize: [5, "day"] } }
});
}
plotWithOptions();
});
该图似乎显示原始刻度,仅此而已
示例数据:
var total = [[634754880000000000,12],[634755744000000000,10],];
var attention = [[634754880000000000,2],[634755744000000000,0],];
var notify = [[634754880000000000,2],[634755744000000000,10],];
var complete = [[634754880000000000,3],[634755744000000000,10],];
var fail = [[634754880000000000,5],[634755744000000000,0],];