我的图表不会读取数组数据,除非我在通过JSON网址获取数据时遇到断点。如果我正在调试,则图表可以显示,否则,则为空白。请帮忙。谢谢!
<script>
var labels = [];
var payments = [];
jQuery.getJSON("<?=base_url()?>Admin/getJSONWeeklyDates", function(data) {
labels = data;
});
jQuery.getJSON("<?=base_url()?>Admin/getJSONWeeklyPayments", function(data) {
payments = data;
});
</script>
<script>
( function ( $ ) {
"use strict";
// single bar chart
var ctx = document.getElementById( "singelBarChart" );
ctx.height = 150;
var myChart = new Chart( ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [
{
label: "Payments",
data: payments,
borderColor: "rgba(0, 123, 255, 0.9)",
borderWidth: "0",
backgroundColor: "rgba(0, 123, 255, 0.5)"
}
]
},
options: {
scales: {
yAxes: [ {
ticks: {
beginAtZero: true
}
} ]
}
}
} );
} )( jQuery );
</script>
注意:当我在控制台上登录标签和付款的数组长度时,即使在页面加载后通过控制台访问该数组时,它具有2个值,它仍显示为0。