gpt4 book ai didi

javascript - Kendo、TypeScript 定义错误 :

转载 作者:行者123 更新时间:2023-11-28 00:08:27 25 4
gpt4 key购买 nike

我正在使用下面所示的语法在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com