我刚刚开始使用高图表(时间序列可缩放),并且我有一个 JSON 数据,如下所示:
[
{"StartTime":"2018-06-11T00:00:00","TotalReq":10},
{"StartTime":"2018-06-12T00:00:00","TotalReq":34},
{"StartTime":"2018-06-15T00:00:00","TotalReq":31},
{"StartTime":"2018-06-16T00:00:00","TotalReq":2},
{"StartTime":"2018-06-18T00:00:00","TotalReq":38},
{"StartTime":"2018-06-19T00:00:00","TotalReq":69},
{"StartTime":"2018-06-20T00:00:00","TotalReq":39},
{"StartTime":"2018-06-21T00:00:00","TotalReq":100},
{"StartTime":"2018-06-22T00:00:00","TotalReq":180},
{"StartTime":"2018-06-25T00:00:00","TotalReq":104},
{"StartTime":"2018-06-26T00:00:00","TotalReq":101},
{"StartTime":"2018-06-27T00:00:00","TotalReq":123}
]
我试图将 StartTime (日期)作为我的x轴参数,并将 TotalReq (计数)作为我的y轴参数。
但是由于某种原因,当我将此数据传递到图形时,它不会将数据加载到图形(黑屏)。我在哪里出错了?纠正我,如果是的话。提前非常感谢。
这是我目前正在研究的图表中的工作示例。 Jsfiddle.
答案 0 :(得分:1)
高级图表需要以毫秒为单位的时间。
因此,您的选择是在javascript中转换字符串,如下所示:
new Date("2018-06-27T00:00:00").getTime()
这意味着您将在整个表格中执行以下操作:
var arr = [
{"StartTime":"2018-06-11T00:00:00","TotalReq":10},
{"StartTime":"2018-06-12T00:00:00","TotalReq":34},
{"StartTime":"2018-06-15T00:00:00","TotalReq":31},
{"StartTime":"2018-06-16T00:00:00","TotalReq":2},
{"StartTime":"2018-06-18T00:00:00","TotalReq":38},
{"StartTime":"2018-06-19T00:00:00","TotalReq":69},
{"StartTime":"2018-06-20T00:00:00","TotalReq":39},
{"StartTime":"2018-06-21T00:00:00","TotalReq":100},
{"StartTime":"2018-06-22T00:00:00","TotalReq":180},
{"StartTime":"2018-06-25T00:00:00","TotalReq":104},
{"StartTime":"2018-06-26T00:00:00","TotalReq":101},
{"StartTime":"2018-06-27T00:00:00","TotalReq":123}]
arr.map(function(data) { return {x: new Date(data.StartTime).getTime(), y: data.TotalReq }})
哪个返回该日期的毫秒值。或在C#中执行。
工作中的JSFiddle示例: https://jsfiddle.net/ewolden/rxLkn2u5/