我有下面的C#代碼:顯示日期
public JsonResult Graph()
{
var result = new Dictionary<DateTime, decimal> { { DateTime.Today.ToUniversalTime(), 1000 }, { DateTime.Today.AddDays(-1).ToUniversalTime(), 2000 }, { DateTime.Today.AddDays(-2).ToUniversalTime(), 5000 } };
return Json(result.ToArray(), JsonRequestBehavior.AllowGet);
}
當我看着螢火蟲的JSON數據是這樣的:
[{"Key":"\/Date(1319515200000)\/","Value":1000},{"Key":"\/Date(1319428800000)\/","Value":2000},{"Key":"\/Date(1319342400000)\/","Value":5000}]
我Highcharts配置看起來像:
var options = {
chart: {
renderTo: 'chart',
},
xAxis: {
type: 'datetime'
},
series: []
}
jQuery.getJSON("/graph", null, function (items) {
var series = {
type: 'column',
data: []
};
jQuery.each(items, function (itemNo, item) {
series.data.push({
name: item.Key,
y: item.Value
})
});
options.series.push(series);
chart = new Highcharts.Chart(options);
chart.render();
});
x軸不會顯示我的日期。任何幫助深表感謝。
謝謝,但沒有奏效。 – Thomas
@Thomas:你有沒有試過'alert(item.Key);'看到'item.Key'的內容? –
是的,它包含1319342400000,但它不在x軸上顯示。 – Thomas