javascript - Kendo、TypeScript 定义错误 :

标签 javascript telerik typescript kendo-chart

我正在使用下面所示的语法在 TypeScript 文件中创建 Kendo Chart(取自 http://demos.telerik.com/kendo-ui/bar-charts/index ):

function createChart() {
            $("#chart").kendoChart({
                title: {
                    text: "Site Visitors Stats \n /thousands/"
                },
                legend: {
                    visible: false
                },
                seriesDefaults: {
                    type: "bar"
                },
                series: [{
                    name: "Total Visits",
                    data: [56000, 63000, 74000, 91000, 117000, 138000]
                }, {
                    name: "Unique visitors",
                    data: [52000, 34000, 23000, 48000, 67000, 83000]
                }],
                valueAxis: {
                    max: 140000,
                    line: {
                        visible: false
                    },
                    minorGridLines: {
                        visible: true
                    },
                    labels: {
                        rotation: "auto"
                    }
                },
                categoryAxis: {
                    categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
                    majorGridLines: {
                        visible: false
                    }
                },
                tooltip: {
                    visible: true,
                    template: "#= series.name #: #= value #"
                }
            });
        }

当我这样做时,我收到以下错误,这似乎表明 ChartOptions 应该是一个数组:

"Error 70 Argument of type '{ title: { text: string; }; legend: { visible: boolean; }; seriesDefaults: { type: string; }; ser...' is not assignable to parameter of type 'ChartOptions'. Types of property 'categoryAxis' are incompatible. Type '{ [x: number]: undefined; categories: string[]; majorGridLines: { visible: boolean; }; }' is not assignable to type 'ChartCategoryAxisItem[]'. Property 'length' is missing in type '{ [x: number]: undefined; categories: string[]; majorGridLines: { visible: boolean; }; }'."

如果我如下所示修改 createChart 函数,错误就会消失,但图表不会呈现:

function createChart() {
            $("#chart").kendoChart([{ //Notice opening array bracket
                title: {
                    text: "Site Visitors Stats \n /thousands/"
                },
                legend: {
                    visible: false
                },
                seriesDefaults: {
                    type: "bar"
                },
                series: [{
                    name: "Total Visits",
                    data: [56000, 63000, 74000, 91000, 117000, 138000]
                }, {
                    name: "Unique visitors",
                    data: [52000, 34000, 23000, 48000, 67000, 83000]
                }],
                valueAxis: {
                    max: 140000,
                    line: {
                        visible: false
                    },
                    minorGridLines: {
                        visible: true
                    },
                    labels: {
                        rotation: "auto"
                    }
                },
                categoryAxis: {
                    categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
                    majorGridLines: {
                        visible: false
                    }
                },
                tooltip: {
                    visible: true,
                    template: "#= series.name #: #= value #"
                }
            }]); // And closing array
        }

还有其他人遇到过这个问题吗?在我看来,这是定义文件中的错误?

最佳答案

我能够通过将 valueAxis 和categoryAxis 值定义为数组来解决该问题,如下所示:

function createChart() {
            $("#chart").kendoChart({
                title: {
                    text: "Site Visitors Stats \n /thousands/"
                },
                legend: {
                    visible: false
                },
                seriesDefaults: {
                    type: "bar"
                },
                series: [{
                    name: "Total Visits",
                    data: [56000, 63000, 74000, 91000, 117000, 138000]
                }, {
                    name: "Unique visitors",
                    data: [52000, 34000, 23000, 48000, 67000, 83000]
                }],
                valueAxis: [{
                    max: 140000,
                    line: {
                        visible: false
                    },
                    minorGridLines: {
                        visible: true
                    },
                    labels: {
                        rotation: "auto"
                    }
                }],
                categoryAxis: [{
                    categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
                    majorGridLines: {
                        visible: false
                    }
                }],
                tooltip: {
                    visible: true,
                    template: "#= series.name #: #= value #"
                }
            });
        }

关于javascript - Kendo、TypeScript 定义错误 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31122611/

相关文章:

javascript - 单击带有 href 属性的链接并执行 Javascript 函数

javascript - 如何计算 RadGrid 中的记录数? (客户端、AJAX)

typescript - 直接使用条件类型与泛型使用时的结果不同

javascript - "regular"客户端开发可以使用编译为 JavaScript 的工具吗?

c# - 在 RadGridView C# 中突出显示空值单元格

javascript - RequireJS 没有使用 karma 和 typescript 正确加载模块

javascript - angularjs 过滤器(不工作)

javascript - React.js 'x' 被分配了一个值但从未使用过 no-unused-vars

javascript - 用 jest 测试 React 中的异步方法

kendo-ui - Kendo UI 级联组合框 : Child not disabled on clearing parent combobox