我正在使用chart.js并且遇到问题过滤结果。我的wep页面有几个子页面,它们只是主页面的过滤版本。触发过滤器时,图表值会发生变化。如果过滤后的页面没有值,则返回主页总数,它似乎也没有刷新。在主页面上会出现一个应该存在的值,但在每个已过滤的页面上,即使var_dump表示未调用该值,该值仍会显示。有没有办法刷新或重绘?
<script>
var compareConfig = {
type: 'line',
data: {
labels: [<?php
$lMonth = 0;
foreach ($lastYrData as $lastMo){
if ($lMonth < 11){
echo '"'.$lastMo['month'].'",';
}else{
echo '"'.$lastMo['month'].'"';
}
++$lMonth;
}
echo '],'."\n";
?>
datasets: [{
label: "<?php echo date('Y', strtotime("-1 year", time()));?>",
fill: true,
borderColor: window.chartColors.green,
data: [
<?php
$lTotal = 0;
foreach ($lastYrData as $lastYrs){
if ($lTotal < 11){
echo '"'.$lastYrs['total'].'",';
}else{
echo '"'.$lastYrs['total'].'"';
}
++$lTotal;
}
?>],
}, {
label: "<?php echo date('Y', time());?>",
borderColor: window.chartColors.blue,
data: [
<?php
$tTotal = 0;
foreach ($thisYrData as $thisYr){
if ($tTotal < 11){
echo $thisYr['total'].',';
}else{
echo $thisYr['total'];
}
++$tTotal;
}
?>
],
fill: true,
}]
},
options: {
responsive: true,
title:{
display:false,
text:''
},
tooltips: {
mode: 'index',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
display: true,
scaleLabel: {
display: false,
labelString: 'Month'
}
}],
yAxes: [{
ticks: {
beginAtZero: true,
userCallback: function(value, index, values) {
value = value.toString();
value = value.split(/(?=(?:...)*$)/);
value = value.join('.');
return '$' + value;
}
},
display: true,
scaleLabel: {
display: false,
labelString: '$ Totals',
}
}]
}
}
};
</script>