1
votes

I am creating a Kendo Chart within a TypeScript file using the syntax shown below (taken from 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 #"
                }
            });
        }

When I do this, I get the following error, which seems to indicate that ChartOptions is expected to be an array:

"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; }; }'."

If I modify the createChart function as shown below, the error goes away, but the chart does not render:

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
        }

Has anyone else encountered this issue? Seems to me to be a bug in the definition file?

2

2 Answers

1
votes

I was able to resolve the issue by defining the valueAxis and categoryAxis values as arrays as shown below:

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 #"
                }
            });
        }
0
votes

I have created a patch for this type definition that allows the exact code you are using.

It is too big to place on Stack Overflow, so the patch is here: https://github.com/Steve-Fenton/DefinitelyTyped/blob/patch-1/kendo-ui/kendo-ui.d.ts

If your code works alongside this definition, I can send a pull request to the Definitely Typed project to have it updated (so it will be available as a NuGet package etc).