Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 然后,使用getJSON。不调用数组?_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 然后,使用getJSON。不调用数组?

Javascript 然后,使用getJSON。不调用数组?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我使用的是“chart.js”;首先调用我的数据图,然后到达我的“$.getJSON”数据请求。我认为我没有正确地将字符串放入数组“ChartData”。我的控制台日志正在到达所需的数据字符串。在“$.getJSON”之后立即调用函数的语法是否不正确? 任何帮助都将不胜感激。多谢各位 const BASE\u URL=”https://zagster-service.herokuapp.com" const G5_TC=“/rides/count/G5” const COL_TC=“/ride

我使用的是“chart.js”;首先调用我的数据图,然后到达我的“$.getJSON”数据请求。我认为我没有正确地将字符串放入数组“ChartData”。我的控制台日志正在到达所需的数据字符串。在“$.getJSON”之后立即调用函数的语法是否不正确? 任何帮助都将不胜感激。多谢各位

const BASE\u URL=”https://zagster-service.herokuapp.com"
const G5_TC=“/rides/count/G5”
const COL_TC=“/rides/count/columbia_simpson”
const DRAKE_TC=“/rides/count/DRAKE_park”
const GALV_TC=“/rides/count/galveston”
const GRC_TC=“/rides/count/GRC”
const OLD_TC=“/rides/count/OLD_mill”
const OSU_TC=“/rides/count/OSU级联”
const TEN_TC=“/rides/count/TEN_barrel”
var ChartData=[];
$(更新视图)
函数updateView(){
美元。什么时候(
$.getJSON(基本URL+G5\u TC,updateChartData00),
$.getJSON(基本URL+COL\u TC,updateChartData01),
$.getJSON(基本URL+DRAKE\u TC,updateChartData02),
$.getJSON(基本URL+GALV\U TC,updateChartData03),
$.getJSON(基本URL+GRC\U TC,updateChartData04),
$.getJSON(基本URL+旧TC,updateChartData05),
$.getJSON(基本URL+OSU\u TC,updateChartData06),
$.getJSON(基本URL+TEN\u TC,updateChartData07)
)。然后(显示图形);
}
函数updateChartData00(数据){
控制台日志(数据);
ChartData.push(data.count)
}
函数updateChartData01(数据){
控制台日志(数据);
ChartData.push(data.count)
}
函数updateChartData02(数据){
控制台日志(数据);
ChartData.push(data.count)
}
函数updateChartData03(数据){
控制台日志(数据);
ChartData.push(data.count)
}
函数updateChartData04(数据){
控制台日志(数据);
ChartData.push(data.count)
}
函数updateChartData05(数据){
控制台日志(数据);
ChartData.push(data.count)
}
函数updateChartData06(数据){
控制台日志(数据);
ChartData.push(data.count)
}
函数updateChartData07(数据){
控制台日志(数据);
ChartData.push(data.count)
}
/*
控制台日志字符串
函数updateChartData00(数据){
console.log(数据)
}
函数updateChartData01(数据){
console.log(数据)
}
函数updateChartData02(数据){
console.log(数据)
}
函数updateChartData03(数据){
console.log(数据)
}
函数updateChartData04(数据){
console.log(数据)
}
函数updateChartData05(数据){
console.log(数据)
}
函数updateChartData06(数据){
console.log(数据)
}
函数updateChartData07(数据){
console.log(数据)
}
功能图表数据(数据){
console.log(数据)
}
*/
/*可视化JS-源代码:https://www.chartjs.org/docs/latest/charts/bar.html" */
函数displayGraph(){
var ctx=document.getElementById(“myChart”).getContext(“2d”)
var myChart=新图表(ctx{
类型:'bar',
数据:{
标签:[“G5”、“Columbia/Simpson”、“Drake Park”、“Galveston”、“GRC”、“Old Mill”、“OSU Cascades”、“十桶”],
数据集:[{
标签:“每个车站的乘车总次数”,
数据:图表数据,
背景颜色:[
"rgba(255,99,132,0.2)",,
“rgba(54162235,0.2)”,
"rgba(255,206,86,0.2)",,
“rgba(751921920.2)”,
“rgba(153102255,0.2)”,
"rgba(255,159,64,0.2)",,
"rgba(58112,42,0.2)",,
‘rgba(76212,40,0.2)’
],
边框颜色:[
"rgba(255,99132,1)",,
“rgba(54162235,1)”,
"rgba(255,206,86,1)",,
"rgba(751921921)",,
"rgba(153102255,1)",,
"rgba(255,159,64,1)",,
“rgba(541622171)”,
'rgba(76242,40,1)'
],
边框宽度:1
}]
},
选项:{
图例:{
标签:{
fontColor:'白色',
字体大小:15.5
}
},
比例:{
xAxes:[{网格线:{
显示:假,
颜色:“rgba(255255,0.8)”
},
滴答声:{
fontColor:'白色',
尺寸:14
}
}]  ,
雅克斯:[{
滴答声:{
贝吉纳泽罗:是的,
fontColor:'白色',
尺寸:14
},
网格线:{
显示:假,
颜色:“rgba(255255,0.8)”
},  
}]
}
}
});
}
/*下拉功能导航条------**来源**:https://www.w3schools.com/css/css_dropdowns.asp" */
函数myFunction(){
document.getElementById(“myDropdown”).classList.toggle(“show”);
}
//如果用户在下拉列表之外单击,请关闭下拉列表------**Source**:https://www.w3schools.com/css/css_dropdowns.asp" //
window.onclick=函数(e){
如果(!e.target.matches('.dropbtn')){
var myDropdown=document.getElementById(“myDropdown”);
if(myDropdown.classList.contains('show')){
myDropdown.classList.remove('show');
}
}

}
试试看。我相信您关于异步代码和推动ChartData数组导致事情无法按预期工作的说法是正确的

const BASE\u URL=”https://zagster-service.herokuapp.com"
const G5_TC=“/rides/count/G5”
const COL_TC=“/rides/count/columbia_simpson”
const DRAKE_TC=“/rides/count/DRAKE_park”
const GALV_TC=“/rides/count/galveston”
const GRC_TC=“/rides/count/GRC”
const OLD_TC=“/rides/count/OLD_mill”
const OSU_TC=“/rides/count/OSU级联”
const TEN_TC=“/rides/count/TEN_barrel”
var ChartData=[];
$(更新视图)
函数updateView(){
美元。什么时候([
($.getJSON(基本URL+G5_TC,updateChartData)),
($.getJSON(基本URL+C