我正在使用Kendo创建一个图表并遇到了问题。
我收到大量数据并将其传递到图表中,数据有日期和值,我的js看起来像这样:
chart.kendoChart({
title: {
text: "title"
},
seriesDefaults: {
type: "line"
},
dataSource: {
data: []
},
series: [{
name: "Value",
field: "value"
}]
categoryAxis: [{
type: "date",
field: "date",
baseUnit: "months",
min: "2013-07-22T00:00:00",
max: "2014-07-22T00:00:00"
}]
});
问题是,如果没有返回数据(即上面的空数组),我仍然希望在底部看到月份日期标签,但是那里没有任何内容(仍然有默认值标签) y轴)。
我查看了Kendo文档,但在stackoverflow上找不到任何内容,也没有任何类似的问题。有人可以帮忙吗?如果有任何我需要澄清/提供的内容,请在评论中告诉我。感谢。
答案 0 :(得分:1)
在没有数据的月份内使用空值填充数据可以解决您的问题。
请参阅此Fiddle作为示例:
另见以下示例代码:
var _data=[{"weight":200,"createddate":"1/1/2014"},
{"weight":200,"createddate":"2/1/2014"},
{"weight":200,"createddate":"3/1/2014"},
{"weight":149.91,"createddate":"4/1/2014"},
{"weight":null,"createddate":"5/1/2014"},
{"weight":null,"createddate":"6/1/2014"},
{"weight":null,"createddate":"7/1/2014"},
{"weight":null,"createddate":"8/1/2014"},
{"weight":null,"createddate":"9/1/2014"},
{"weight":null,"createddate":"10/1/2014"},
{"weight":null,"createddate":"11/1/2014"},
{"weight":null,"createddate":"12/1/2014"}]
$("#kk").kendoChart({
dataSource: {
data:_data
},
seriesColors: ["Red"],
seriesDefaults: {
type: "column",
},
series: [{
name: "weight",
field: "weight",
categoryField: "createddate",
}],
categoryAxis: {
type: "date",
baseUnit: "months"
}
});