如何在脚本中显示数据?
这是我当前的代码,问题是我不知道如何返回值,我不知道为什么我的函数的作者未定义,我想要的是从查询中获取数据并将其传递给 const reportChart,请帮忙,谢谢
这是我的完整代码吗?我错过了什么吗?
<script>
async function myFunction() {
var author = ("SELECT name FROM People", 10, (value)=>{
console.log(value)//please see the data below
return value;
})
return author; //undefined
}
myFunction().then(function(value){reportChart(value);})
const reportChart = (value) => {
console.log("inside chart: ",value) //The value of value is undefined
$("#chart").kendoChart({
title: {
text: "School Library"
},
legend: {
visible: false
},
seriesDefaults: {
type: "bar"
},
series: [{
name: "Total Visits",
data: [1, 2, 3]
}, {
name: "Total Visits",
data: [1, 2, 3]
}],
valueAxis: {
max: 10,
line: {
visible: false
},
minorGridLines: {
visible: true
},
labels: {
rotation: "auto"
}
},
categoryAxis: {
categories: [value],//undefined
majorGridLines: {
visible: false
}
},
tooltip: {
visible: true,
template: "#= series.name #: #= value #"
}
});
}
$(document).ready(reportChart);
$(document).bind("kendo:skinChange", reportChart);
</script>
console.log(value) 的结果
0: ['马克'] 1: ['约瑟夫'] 2: ['卢娜'] 3: ['尤诺']
更新
我删除了一些代码并替换了这个
<script>
let myPromise = new Promise(function(myResolve, myReject){
var author = ("SELECT name FROM People", 10, (value) => {
return myResolve(value)
});
})
myPromise.then(
function(value) {reportChart(value);},
function(error) {reportChart(error);}
);
function reportChart (value, index) {
console.log(index, value.length)
var i = 0
var author= []
for(i=0; i<=value.length; i++)
{
author[i] = value[i]
}
$("#chart").kendoChart({
title: {
text: "Library"
},
legend: {
visible: false
},
seriesDefaults: {
type: "bar"
},
series: [{
name: "Total Visits",
data: [1,2,3,4]
}, {
name: "Total Visits",
data: [4,5,6,7]
}],
valueAxis: {
max: 10,
line: {
visible: false
},
minorGridLines: {
visible: true
},
labels: {
rotation: "auto"
}
},
categoryAxis: {
categories: [author],
majorGridLines: {
visible: false
}
},
tooltip: {
visible: true,
template: "#= series.name #: #= value #"
}
});
}
$(document).ready(reportChart);
$(document).bind("kendo:skinChange", reportChart);
</script>
**
这就是现在的结果
我想要的是,请帮忙
This is my current code, the problem is I dont know how to return the value, i dont know why the author from my function are undefined, what i want is to get the data from my query and pass it to the const reportChart
, please help, thanks
this is my full code? did i miss something?
<script>
async function myFunction() {
var author = ("SELECT name FROM People", 10, (value)=>{
console.log(value)//please see the data below
return value;
})
return author; //undefined
}
myFunction().then(function(value){reportChart(value);})
const reportChart = (value) => {
console.log("inside chart: ",value) //The value of value is undefined
$("#chart").kendoChart({
title: {
text: "School Library"
},
legend: {
visible: false
},
seriesDefaults: {
type: "bar"
},
series: [{
name: "Total Visits",
data: [1, 2, 3]
}, {
name: "Total Visits",
data: [1, 2, 3]
}],
valueAxis: {
max: 10,
line: {
visible: false
},
minorGridLines: {
visible: true
},
labels: {
rotation: "auto"
}
},
categoryAxis: {
categories: [value],//undefined
majorGridLines: {
visible: false
}
},
tooltip: {
visible: true,
template: "#= series.name #: #= value #"
}
});
}
$(document).ready(reportChart);
$(document).bind("kendo:skinChange", reportChart);
</script>
the result of console.log(value)
0: ['Mark'] 1: ['Joseph'] 2: ['Luna'] 3: ['Yuno']
Update
I remove some code and replace this
<script>
let myPromise = new Promise(function(myResolve, myReject){
var author = ("SELECT name FROM People", 10, (value) => {
return myResolve(value)
});
})
myPromise.then(
function(value) {reportChart(value);},
function(error) {reportChart(error);}
);
function reportChart (value, index) {
console.log(index, value.length)
var i = 0
var author= []
for(i=0; i<=value.length; i++)
{
author[i] = value[i]
}
$("#chart").kendoChart({
title: {
text: "Library"
},
legend: {
visible: false
},
seriesDefaults: {
type: "bar"
},
series: [{
name: "Total Visits",
data: [1,2,3,4]
}, {
name: "Total Visits",
data: [4,5,6,7]
}],
valueAxis: {
max: 10,
line: {
visible: false
},
minorGridLines: {
visible: true
},
labels: {
rotation: "auto"
}
},
categoryAxis: {
categories: [author],
majorGridLines: {
visible: false
}
},
tooltip: {
visible: true,
template: "#= series.name #: #= value #"
}
});
}
$(document).ready(reportChart);
$(document).bind("kendo:skinChange", reportChart);
</script>
**
this is now the result
What I want is, please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里:
listsOfPeople = value
,我想您想要的是listsOfPeople.push(value);
?您的代码应类似于
varauthor = doQuery("SELECT name FROM People"....
可能的问题:
doQuery()
意外更改listsOfPeople
或者listsOfPeople
和listsOfAuthor
。Here:
listsOfPeople = value
, I guess what you would like to to islistsOfPeople.push(value);
instead?Your code should be like
var author = doQuery("SELECT name FROM People"....
Possible issues:
doQuery()
changeslistsOfPeople
unexpectedly.listsOfPeople
andlistsOfAuthor
.