唯一拥有所有刻度的方法是在图表数据中附加缺失月份的空值。因此,当您获得一个数据点时,您需要将其他数据点附加为空值,但保留其他月份。请看下面的示例代码:
<div id="kk"></div>
<script>
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"
}
});
</script>
请找到相同的JSFiddle。这样,当您从控制器获取 JSON 数据时,您可以在控制器端更新 JSON 数据并使用 null 值附加缺失的数据点,或者您也可以在视图中获取数据并在绑定之前在 javascript 中执行此操作它与图表。