2

我正在使用剑道制作图表并且遇到了问题。

我正在获取大量数据并将其传递到图表中,数据有一个日期和一个值,我的 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 的任何类似问题。任何人都可以帮忙吗?如果有什么我需要澄清/提供的,请在评论中告诉我。谢谢。

4

1 回答 1

1

使用没有数据的月份的空值填充您的数据可以解决您的问题。

请以这个小提琴为例:

另请参阅下面的示例代码:

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"
            }                        
        });
于 2014-08-28T13:37:22.247 回答