charts - 未捕获的类型错误 : Cannot read property 'length' of undefined (Kendo Chart)

标签 charts kendo-ui

我的剑道图表有问题,当从 Controller 返回的项目列表没有项目时,我出现错误:

Uncaught TypeError: Cannot read property 'length' of undefined kendo.all.min.js:28
    Vt.extend._bindCategoryAxis kendo.all.min.js:28
    Vt.extend._bindCategories kendo.all.min.js:28
    Vt.extend._onDataChanged kendo.all.min.js:28
    b.isFunction.i jquery-1.9.1.min.js:3
    i.extend.trigger kendo.all.min.js:9
    tt.extend._process kendo.all.min.js:11
    tt.extend.success kendo.all.min.js:11
    b.isFunction.i jquery-1.9.1.min.js:3
    n.success kendo.all.min.js:11
    c jquery-1.9.1.min.js:3
    p.fireWith jquery-1.9.1.min.js:3
    k jquery-1.9.1.min.js:5
    r jquery-1.9.1.min.js:5

如果我从代码中删除categoryAxis,一切都会按预期工作,无论是否没有数据,但问题是我不会在x轴上表示时间:

function createChart() {
    $("#chart").kendoChart({
        dataSource: {
            transport: {
                read: {
                    url: "@Url.Action("GetLostDaysTrend", "Production")"+"?
                        initDate="+startDate+"&endDate="+endDate+"&reactor="+reactor                             
                    ,contentType: "application/json",
                    type: "POST"
                 },
                 parameterMap: function (options) {
                     return JSON.stringify(options);
                 }
            },
            group: {
                field: "Reactor"
            },
            sort: {
                field: "Fecha",
                dir: "asc"
            }
        },
        title: {
            text: "Tendencias de dias perdidos"
        },
        legend: {
            position: "top"
        },
        seriesDefaults: {
            type: "line"
        },
        series:
        [{
            field: "Acumulado",
            name: "Acumulado",
            groupNameTemplate: "#= group.value # (#= series.name #)"
        }],
        categoryAxis: {
            field: "Fecha",
            labels: {
                template: "#= formatDate(value) #",
                rotation: -90
            }
        },
        tooltip: {
           visible: true,
           format: "N0"
        }
    });
}

这个问题让我很头疼,有什么线索吗?

最佳答案

遇到了同样的问题,并通过检查数组的长度是否非零来修复它:

parameterMap: function (options) {
...

    if (options.sort.length == 0) {
    return [];
    }
    else {
    return options.sort[0].field + ',' + options.sort[0].dir;
    }
}

关于charts - 未捕获的类型错误 : Cannot read property 'length' of undefined (Kendo Chart),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16454646/

相关文章:

crystal-reports - 如何有条件地更改 Crystal 报表图表中的轴刻度?

javascript - 在 'load' 而不是鼠标事件上调用 D3.JS 函数

kendo-ui - 如何删除 Kendo 网格中的多行?

asp.net-mvc - 我如何从剑道组合框中获得选择值

javascript - Chart Js 更改 Ox 轴上的文本标签方向

javascript - Highcharts:如何将完整数据添加到图表中的多个系列

swift - Swift 的 ios-charts 图表 - 故意流血/溢出图表条

javascript - 在 Kendo UI Scheduler 中隐藏时间行

angularjs - Kendo 树列表显示无记录的自定义消息

jquery - 使用 id 打开 Kendo UI TreeView 节点